javascript - how to get local date/time format? -


i want systems local date/time format , display date database on same format. e.g if system date format month dd/yyyy , date stored in database mm/dd/yyyy format need local date/time format , convert stored date local format. html5 input type="date" takes default systems date/time format , show date in same format. how can jquery or javascript.

you use javascript date object:

var date = new date(yearfromdb, monthfromdb, dayfromdb); date.tolocaledatestring(); 

edit

it seems above method not consistent between different browsers (chrome, ie, firefox). therefore, think option formatted date string server side.

here jsfiddle shows cross-browser way of getting users locale, if can use formatted date string in current locale backend (if any).

var locale = window.navigator.userlanguage || window.navigator.language; 

Comments