Chrome, JS and displaying dates

Gudday all
Just started the last few days looking at my wife’s site using Chrome. A few minutes ago I noticed that it was not displaying dates correctly.
In Chrome

the date comes out as ‘Last updated on / /’


the date comes out as ‘Last updated on dd/ mm/yyyy’

The JS is

<script type="text/javascript">
var now =  new Date();
document.write('<p class="webmaster">');
document.write("Site design &copy; Petals &amp; Patches 2004 -" + now.getFullYear() + ".");
document.write('<p class="lastupdated">');
document.write("Last updated on " + document.lastModified.substring(3,5) + "/" + document.lastModified.substring(0,2)+ "/" + document.lastModified.substring(6,10) + '<\\/p>');

Looking at my code I can see no blindingly obvious problem.
I am sure that this has been noted and solved but a search of the fora came up with nothing. (my search was probably not very good :frowning: )

Any advice greatly appreciated.

The way to test this is to read the return value of document.lastModified.
There is no standard shared between browsers, and to be safe you might just use the value returned.

At least test the value to see if your substrings make sense.
I get these values, in windows for these versions, but there are many other combinations.

‘03/20/2010 12:14:47’ //IE8, firefox 3
‘Sat, 20 Mar 2010 16:14:47 GMT’ //opera 10, chrome 2, safari 4

Thanks Mrhoo
I was hoping that a standard would exist for date displaying. :eek:

Looks like I’ll have to put some code in to determine what browser is in use and modify the code accordingly.

You could make a date object of whatever returned string you get-

var s=‘’,d=new Date(Date.parse(document.lastModified));
s+= [d.getFullYear(),d.getMonth()+1,d.getDate()].join(‘/’);