Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Date modified & DST

Date modified & DST

Date modified & DST


I have some javascript below that reports the time since the html file was generated. This was all working fine until DST, where it started showing the Last Updated time as an hour behind the actual time.
I believe I understand the concept of javascript time (i.e. milliseconds since 1 Jan 1970), but I just can't seem to apply the DST correction correctly. I did manage to correct part of the code so that it shows the correct time difference between the file being modified & the current time, but the hour is still out on the last updated timestamp. I know I could just add 1 to the hour value, but I was hoping to be able to have the code apply the appropriate timezone value.

CODE --> javascript

function timer()
var lastmod = new Date(document.lastModified);
var lm_day = ('0' + lastmod.getDate()).slice(-2);
var lm_month = ('0' + (lastmod.getMonth()+1)).slice(-2);
var lm_year = lastmod.getFullYear();
var lm_hour = ('0' + lastmod.getHours()).slice(-2);
var lm_minute = ('0' + lastmod.getMinutes()).slice(-2);
var lm_second = ('0' + lastmod.getSeconds()).slice(-2);
var lm_formatted = lm_day+"/"+lm_month+"/"+lm_year+" "+lm_hour+":"+lm_minute+":"+lm_second;
var lm_formatted_for_js = lm_year+"/"+lm_month+"/"+lm_day+" "+lm_hour+":"+lm_minute+":"+lm_second;
var currentDateTime = new Date();
currentTimeIncTimezone = currentDateTime.getTime()+(currentDateTime.getTimezoneOffset()*60*1000);
var nd = new Date(currentTimeIncTimezone);
var day = ('0' + nd.getDate()).slice(-2);
var month = ('0' + (nd.getMonth()+1)).slice(-2);
var year = nd.getFullYear();
var hour = ('0' + nd.getHours()).slice(-2);
var minute = ('0' + nd.getMinutes()).slice(-2);
var second = ('0' + nd.getSeconds()).slice(-2);
var currentTime_Formatted = day+"/"+month+"/"+year+" "+hour+":"+minute+":"+second;
var currentTime_Formatted_for_js = year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second;
var diff = Math.abs(new Date(lm_formatted_for_js) - new Date(currentTime_Formatted_for_js));
var secsago = Math.floor(diff/1000);
var minutes = Math.floor(secsago/60);
var sec_min = ('0' + Math.floor((secsago)%60)).slice(-2);
var min_word = 'minute'
if (minutes != 1) {
var min_word = 'minutes';
var lastupdatedstring = "Last updated: "+lm_formatted+" (";
if (minutes != 0 ) {
lastupdatedstring = (lastupdatedstring+minutes+" "+min_word+" ");
} else {
document.getElementById("dt").innerHTML = lastupdatedstring+sec_min+" seconds ago)"

RE: Date modified & DST

Is the server Locale set to use DST or is it set to UTC?


Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: Date modified & DST

It's using (UTC) Dublin, Edinburgh, Lisbon, London & it shows DST ends on 30 October at 02:00.

RE: Date modified & DST

I think I've found it. (well it appears to work - will see what happens when the clocks go back)!


var lm_hour = ('0' + lastmod.getHours()-(lastmod.getTimezoneOffset() /60))).slice(-2);
//var currentDateTime = new Date();
//currentTimeIncTimezone = currentDateTime.getTime()+(currentDateTime.getTimezoneOffset()*60*1000);
//var nd = new Date(currentTimeIncTimezone);
var nd = new Date();

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close