admin管理员组文章数量:1430551
I want to get systems local date/time format and display date from database on this same format. e.g if system date format is like Month dd/yyyy and date stored in database is mm/dd/yyyy format then I need to get local date/time format and convert my stored date into local format.
HTML5 input type="date"
this takes default systems date/time format and show date in same format. how can I do this with jquery
or javascript
.
I want to get systems local date/time format and display date from database on this same format. e.g if system date format is like Month dd/yyyy and date stored in database is mm/dd/yyyy format then I need to get local date/time format and convert my stored date into local format.
HTML5 input type="date"
this takes default systems date/time format and show date in same format. how can I do this with jquery
or javascript
.
- 2 So what is your question? and what have you tried so far? – Dhaval Marthak Commented Jul 15, 2013 at 6:01
- 1 I want to read local date/time format and display stored date in that format. I am not able to get system date format like mm/dd/yyyy or dd/mm/yyyy etc. – Prasad Commented Jul 15, 2013 at 6:03
- stackoverflow./questions/8469436/… – Satpal Commented Jul 15, 2013 at 6:04
- possible duplicate of JavaScript - Get system short date format – Pekka Commented Jul 15, 2013 at 6:05
-
1
I hope you're not storing a date as a
mm/dd/yyyy
string in your database. You should be storing it as adate
(ordatetime
) - the ANSI SQL format for these isYYYY-MM-DD
(of course this does not address your question about locale settings) – Stephen P Commented Jul 15, 2013 at 6:26
1 Answer
Reset to default 1You could use the JavaScript Date
object:
var date = new Date(yearFromDb, monthFromDb, dayFromDb);
date.toLocaleDateString();
EDIT
It seems that the above method is not consistent between different browsers (Chrome, IE, Firefox). Therefore, I think your only option is to get the formatted date string from server side.
Here is a jsFiddle that shows a cross-browser way of getting the users locale, if you can use this to get a formatted date string in the current locale from the backend (if any).
var locale = window.navigator.userLanguage || window.navigator.language;
本文标签: javascripthow to get local datetime formatStack Overflow
版权声明:本文标题:javascript - how to get local datetime format? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745557932a2663298.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论