Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Python, Lua and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Java, C, C++, Ruby, MySQL and Linux / Tomcat systems
Local and GMT Time Difference

Posted by TedH (TedH), 1 August 2008
Hi, I'm looking at times with a view toward comparing them with a start time, then doing something.

The easiest way would seem to be using the base time (no formatting). There is a lot of difference between these and I wonder which is the best one to use.

Starting date = 33481731610842121
GMTime = 0001070400
LocalTime = 16541731610842121

My code is this
print "Starting date = 33481731610842121<br>\n";
print "GMTime = \n";
print localtime($time);
print "<br>\n";
print "LocalTime = \n";
print localtime(time);

When I refresh, the Local changes, but the GMT does not. Does that mean the GMT is set to the day (disregarding hours minutes and seconds)?

Cheers - Ted

Posted by KevinAD (KevinAD), 1 August 2008
Either I'm confused or you are. You are not calling gmtime anywhere in the code you posted and $time has never been defined. Is this what you meant to do?

print "Starting date = 33481731610842121<br>\n";
print "GMTime = \n";
print gmtime(time);
print "<br>\n";
print "LocalTime = \n";
print localtime(time);

gmtime does return a shorter string than localtime, at least on my computer it does. I don't know why that is. But they both return a 9 element array when called in list context and the same format when called in scalar context.

print "Starting date = 33481731610842121<br>\n";
print "GMTime = \n";
print scalar gmtime(time);
print "<br>\n";
print "LocalTime = \n";
print scalar localtime(time);

Posted by admin (Graham Ellis), 2 August 2008
Little demo ...

This code:

@now = gmtime();
$now = gmtime();
print ("gmtime\n@now\n",@now,"\n","$now\n");

@now = localtime();
$now = gmtime();
print ("\nlocattime\n@now\n",@now,"\n","$now\n");


earth-wind-and-fire:~/aug08 grahamellis$ perl times
34 2 18 1 7 108 5 213 0
Fri Aug  1 18:02:34 2008

34 2 19 1 7 108 5 213 1
Fri Aug  1 18:02:34 2008
earth-wind-and-fire:~/aug08 grahamellis$

It looks very odd as a single number all together which can be a bit confusing; elements are really:
month (0 to 11)
year (from 1900)
day of week
day of year
daylight saving correction

Which to use?   It depends on the context of your server / computer. If you want it to report back in GMT, then use that ... if it's for a UK only applicatin, then use localtime.

Posted by TedH (TedH), 2 August 2008
Hi guys, had major connection problems and it just got sorted (hopefully) by Virgin.

You're right Kevin gmtime was missed out - me figuring out stuff, as I've never used this method before.

Thanks Graham, I can see what stuff does.

There is another one I found that's just "time"and it gives a shorter result. I think that using localtime would be best. Everything is in seconds (I think), and so differences would have to done on that basis. What I'm playing about with is a fake cron thing to activate scripts. Based on a preset date (I'll try to figure out a midnight one). So that oughta tax my brain for a bit (I'm lousy at math)

Thanks - Ted

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2018: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01225 708225 • FAX: 01225 793803 • EMAIL: • WEB: • SKYPE: wellho