What culture does the javascript Date object use?

javascript, jquery

Solution

In basic use without specifying a locale, a formatted string in the default locale and with default options is returned.

var date = new Date(Date.UTC(2012, 11, 12, 3, 0, 0));

// toLocaleString without arguments depends on the implementation,
// the default locale, and the default time zone
date.toLocaleString();
// "12/11/2012, 7:00:00 PM" if run in en-US locale with time zone America/Los_Angeles

Using locales

var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));

// formats below assume the local time zone of the locale;
// America/Los_Angeles for the US

// US English uses month-day-year order
alert(date.toLocaleString("en-US"));
// "12/19/2012, 7:00:00 PM"

// British English uses day-month-year order
alert(date.toLocaleString("en-GB"));
// "20/12/2012 03:00:00"

// Korean uses year-month-day order
alert(date.toLocaleString("ko-KR"));
// "2012. 12. 20. 오후 12:00:00"

Problem

The language of my OS (Windows) is in danish, and so is the language of my browsers. When i am trying to parse a Date in the danish format (dd-MM-yyyy) like this: ``` var x = "18-08-1989" var date = new Date(x); ``` I get the wrong date from javascript (i want 18'th of August 1989). When i transform this string to english, and parse it, it returns the correct date. Does the format of the date string always have to be: yyyy-MM-dd when using the JS Date object??

Original source