0

On my site I use the following code to tell users when I last updated my website:

Last updated: ', new Date(document.lastModified).toLocaleString(), '

This shows users something like this:

Last updated: 22 April 2006 12:53:12

Would it be possible to remove the time, so it just says:

Last updated: 22 April 2006

Thanks
Martin

3
Contributors
12
Replies
13
Views
11 Years
Discussion Span
Last Post by martinkorner
0

OOps - Sorry I missed part of my code out (thought it didn't make sense!)

Here is the real code I currently use:

<script type="text/javascript">
document.write ('Last updated: ', new Date(document.lastModified).toLocaleString())
</script>

But I would like to remove he time from it (as I said above)

Thanks Again
Martin

0

So would I do something like this?

<script type="text/javascript">
document.write ('Last updated: ', getDate(document.lastModified).toLocaleString(), 
getMonth(document.lastModified).toLocaleString(), 
getFullYear(document.lastModified).toLocaleString())
</script>

Hope that's right - I've not tested it though, so it's probably completely wrong!

Thanks
Martin

0

Try this:

DLM=new Date(document.lastModified);
DLM_Y=DLM.getYear();
DLM_M=DLM.getMonth(); // Jan-Dec = 0-11
DLM_D=DLM.getDate();
if (DLM_Y < 70)   { DLM_Y=DLM_Y*1+2000; }
if (DLM_Y < 1000) { DLM_Y=DLM_Y*1+1900; }
DLM_M=DLM_M*1+1; // Jan-Dec = 1-12
if (DLM_M*1 < 10) { DLM_M='0'+DLM_M; } // leading zero
if (DLM_D*1 < 10) { DLM_D='0'+DLM_D; }
Out=DLM_M+'-'+DLM_D+'-'+DLM_Y;
document.write(Out);
0

That gives me something like:

04-24-2006

But I would still prefer it without the dashes and in english order (dd-mm-yyyy) instead of American order (mm-dd-yyyy).
That's simple enough to change:

DLM=new Date(document.lastModified);
DLM_Y=DLM.getYear();
DLM_M=DLM.getMonth(); // Jan-Dec = 0-11
DLM_D=DLM.getDate();
if (DLM_Y < 70) { DLM_Y=DLM_Y*1+2000; }
if (DLM_Y < 1000) { DLM_Y=DLM_Y*1+1900; }
DLM_M=DLM_M*1+1; // Jan-Dec = 1-12
if (DLM_M*1 < 10) { DLM_M='0'+DLM_M; } // leading zero
if (DLM_D*1 < 10) { DLM_D='0'+DLM_D; }
Out=DLM_D+' '+DLM_M+' '+DLM_Y;
document.write(Out);

But I would also like the month to be in text format:

24 April 2006

Can anyone canvert 1 into January, 2 to February etc.?

Martin

0

All of the information you need is in the link I provided above. With all due respect, I encourage you to do some of this work yourself. That's why I pointed you to the reference, rather than writing the code for you.

If you click that link, you'll see a complete list of every date-related Javascript method. Clicking "getMonth()" shows you detailed documenation about that method, including sample code for converting the month-number to a month name.

0

OK - sorry, I just assumed that it only explained what was said in the phrase by the link

Returns the month from a Date object (from 0-11)

Really Sorry ;)

Martin

0

I'm not mad, so no apology necessary. I just know from experience that you learn better by figuring things out yourself. This forum is a great resource for pointers in the right direction, so there was nothing wrong with starting the thread and asking some questions. You have to follow-up on the answers, though!

I hope your project turns out well.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.