JS date-format prob on MAC browsers


I have:
var today = new Date();

prints, in all windows browsers:

Tuesday, January 05, 2010

in MAC browsers prints:

01/05/2010 (Safari - mac)
Tuesday, Jan, 05, 2010 (FF - mac)

how do I solve this for the mac browsers…

thank you…

actually I made a mistake: in Safari (mac) it prints:

January 5, 2010

in FF (mac) it prints:



You can format the string yourself using the other Date object methods, eg getMonth() getDay() etc…

The way the string prints out when you use toLocaleDateString() depends on how the local computer is configured. The idea is that the date prints if the format that your visitor wants rather than some backwards format that they don’t normally use.

If you want full control over the format that dates are displayed in from your code then take a look at http://javascript.about.com/library/bldateformat.htm where I created a format method for JavaScript that works with the PHP style string that orivides the instructions on what the date should look like. Using that you can extract a date in any format you like using one short statement.