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;