admin管理员组文章数量:1287219
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??
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??
Share Improve this question asked May 2, 2013 at 12:55 KenciKenci 4,88216 gold badges69 silver badges113 bronze badges 3- "18-08-89" is not in the "dd-MM-yyyy" format, have you tried "18-08-1989"? – darma Commented May 2, 2013 at 12:57
- blog.stevenlevithan./archives/date-time-format – Ajinkya Commented May 2, 2013 at 12:58
- I corrected my question, and yes I have tried it – Kenci Commented May 2, 2013 at 12:59
2 Answers
Reset to default 8In 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"
Look here form more info about Date object: https://developer.mozilla/en-US/docs/JavaScript/Reference/Global_Objects/Date
And here about format: https://www.rfc-editor/rfc/rfc2822#page-14
本文标签: jqueryWhat culture does the javascript Date object useStack Overflow
版权声明:本文标题:jquery - What culture does the javascript Date object use? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741306276a2371387.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论