Training, Open Source computer languages

This is page http://www.wellho.net/forum/Perl-Programming/Local-an ... rence.html

Our email: info@wellho.net • Phone: 01144 1225 708225

 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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
Code:
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:

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");


returns

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

locattime
34 2 19 1 7 108 5 213 1
342191710852131
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:
second
minute
hour
day
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 www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho