0

Is there any way via HTML5, proprietary apis, or PhoneGap to obtain the date format a given user is likely to want?

I currently display everything as MM/dd/yyyy, but this is confusing for any users who live in dd/MM/yyyy countries.

Stefan Kendall
  • 66,414
  • 68
  • 253
  • 406
  • via javascript since the question is tag with javascript. http://stackoverflow.com/questions/85116/how-do-i-display-a-date-time-in-the-users-locale-format-and-time-offset – Danny Mar 27 '12 at 19:13

2 Answers2

2

I believe you will want to look into the Globalization plugin's getDatePattern method.

https://github.com/phonegap/phonegap-plugins/tree/master/Android/Globalization https://github.com/phonegap/phonegap-plugins/tree/master/BlackBerry/Globalization https://github.com/phonegap/phonegap-plugins/tree/master/iPhone/Globalization

Simon MacDonald
  • 23,253
  • 5
  • 58
  • 74
  • I'm currently using PhoneGap build to avoid the hassle of building, so I hope this isn't the only solution. If it is, then I need to start begging the phonegap build guys to support this plugin. :P +1 regardless. – Stefan Kendall Mar 27 '12 at 19:25
1

The simplest way to determine the local day-month/month-day order is to check it.

You can check once and save it as a boolean to use in any input or output date formatting.

(this returns true if the date should precede the month- feel free to reverse it!).

Date.datefirst= (function(){
    return Date.parse('2/6/2009')> Date.parse('6/2/2009');
})()
kennebec
  • 102,654
  • 32
  • 106
  • 127