3

I am calculating the date using the number of seconds since epoch at UTC.

here is how I am currently doing it:

var LastUpdatedTime = data.LastUpdated;
myDate = new Date(1000 * LastUpdatedTime);                                  
var LastUpdatedTime = myDate.toLocaleString();

In Chrome i see: 2/26/2013 9:57:35 AM

Which is exactly what I want

In Safari I see: February 26, 2013 9:27:34 AM EST

Any advice on how to get Safari to format the date the same way Chrome does?

JJJ
  • 32,902
  • 20
  • 89
  • 102
Xtian
  • 3,535
  • 11
  • 55
  • 91
  • Build the string by hand. `toLocaleString()` does just what it says--it formats the string according to the user's locale (and apparently Safari uses a different locale) so you can't predict what its output will be. – JJJ Feb 26 '13 at 15:04
  • please see http://stackoverflow.com/questions/6427204/date-parsing-in-javascript-is-different-between-safari-and-chrome – topcat3 Feb 26 '13 at 15:04
  • you could try using this library http://zetafleet.com/blog/javascript-dateparse-for-iso-8601 with new Date. May do what you require – topcat3 Feb 26 '13 at 15:09

2 Answers2

0

You can try Datejs

It gives you ways to nicely format days the way you want for example

   new Date().toString('dd/mm/yyyy hh:MM:ss')
Davor Zlotrg
  • 6,020
  • 2
  • 33
  • 51
0

Browsers are free to implement Date's string output functions in any format they like. To achieve a consistent format across browsers you will have to either create your own formatting function or use a third-party library such as Datejs or date.format.js.

By the way, this has nothing to do with jQuery. The problem is that ECMAScript does not define a consistent date formatting mechanism.

dgvid
  • 26,293
  • 5
  • 40
  • 57