0

Possible Duplicate:
How do I display a date/time in the user’s locale format and time offset?

We write things differently, and date is one of these things.
I would like to display A date (not the current one), and format it for everyone, depending on their country.

Guess I could like go and write a new javascript file with all the location checkup and then formatting the given string.. but I'm pretty sure there is a pre-written solution somewhere which is much better than what I could come up with.

Community
  • 1
  • 1
Apache
  • 1,060
  • 5
  • 21
  • 38
  • That was unexpectedly simple. Sorry. Should I close the question? (Why don't you post is an answer?) – Apache Nov 10 '12 at 08:31
  • Next time look at [MDN](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date/toLocaleDateString) – mplungjan Nov 10 '12 at 08:47

1 Answers1

1

Try using:

  // This would come from the server.
// Also, this whole block could probably be made into an mktime function.
// All very bare here for quick grasping.
d = new Date();
d.setUTCFullYear(2004);
d.setUTCMonth(1);
d.setUTCDate(29);
d.setUTCHours(2);
d.setUTCMinutes(45);
d.setUTCSeconds(26);

alert(d);                        // -> Sat Feb 28 2004 23:45:26 GMT-0300 (BRT)
alert(d.toLocaleString());       // -> Sat Feb 28 23:45:26 2004
alert(d.toLocaleDateString());   // -> 02/28/2004
alert(d.toLocaleTimeString());   // -> 23:45:26

Source: Display date/time in user's locale format and time offset

Community
  • 1
  • 1
Markweb
  • 303
  • 3
  • 6