J
Jon
Hello,
I am trying to take a date (day/month/year) and time (hour:min) from
the user, and also a timezone which that date/time is based on. I
then need to pull all logs out of a database which happens on that
supplied date and time.
The log stores everything by its timestamp, which I take from time().
So all the timestamps should be based in UTC time. So first step I
need to do is take the supplied date/time and turn it into a UTC
timestamp.
I do that by setting the $ENV{TZ} to the timezone and then use
timegm(), I remembered to take away -1 from the month.
So I now have what I think is the UTC timestamp of the supplied
time/date. Now here is the problem, I thought I could reverse this,
and turn that timestamp back into the original date/time (in its
timezone).
Again I set the ENV{TZ} and this time use localtime() on the
timestamp. This would return a different date/time compared to the
original. An example of what code I used is as follows.
$ENV{TZ} = ':/usr/share/zoneinfo/Europe/Paris';
$localseconds = timegm(27,11,10,15,8,2003);
print "$localseconds\n";
(11 minutes past 10am, and 27 seconds on the 15th August 2003)
$localseconds is 1063620687.
$ENV{TZ} = ':/usr/share/zoneinfo/Europe/Paris';
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime('1063620687');
Now, it returns 12:11:27 on the 15th. Which is 2 hours out of the
original date and time. Have I got the functions mixed up, or am I
just not on the right track here?
Thank you in advance for any help,
Jon.
I am trying to take a date (day/month/year) and time (hour:min) from
the user, and also a timezone which that date/time is based on. I
then need to pull all logs out of a database which happens on that
supplied date and time.
The log stores everything by its timestamp, which I take from time().
So all the timestamps should be based in UTC time. So first step I
need to do is take the supplied date/time and turn it into a UTC
timestamp.
I do that by setting the $ENV{TZ} to the timezone and then use
timegm(), I remembered to take away -1 from the month.
So I now have what I think is the UTC timestamp of the supplied
time/date. Now here is the problem, I thought I could reverse this,
and turn that timestamp back into the original date/time (in its
timezone).
Again I set the ENV{TZ} and this time use localtime() on the
timestamp. This would return a different date/time compared to the
original. An example of what code I used is as follows.
$ENV{TZ} = ':/usr/share/zoneinfo/Europe/Paris';
$localseconds = timegm(27,11,10,15,8,2003);
print "$localseconds\n";
(11 minutes past 10am, and 27 seconds on the 15th August 2003)
$localseconds is 1063620687.
$ENV{TZ} = ':/usr/share/zoneinfo/Europe/Paris';
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime('1063620687');
Now, it returns 12:11:27 on the 15th. Which is 2 hours out of the
original date and time. Have I got the functions mixed up, or am I
just not on the right track here?
Thank you in advance for any help,
Jon.