Welcome to OnlineConversion.com

unix time conversion wrong?

unix time conversion wrong?
by Benno Schmid on 04/20/05 at 07:25:11

i just tried your unix time conversion application and it seems as if there is something wrong with it.
When i use the last full hour (4/20/2005 13:00:00) i get 1114002000, whereas other converter and the command perl -e "print time - time%3600" give me 1113994800.
I also got wrong results with another time i had to use for a riddle.
Please look at the code again, i don't know javascript so i can't spot the bug.
Greetings, Benno

Re: unix time conversion wrong?
by Robert Fogt on 04/20/05 at 16:54:42

I checked using Perl and it is correct as it is.

I used the following code:

$first_string = gmtime(1113994800);
$second_string = gmtime(1114002000);
print "$first_string\n$second_string";

When run, the output is:
Wed Apr 20 11:00:00 2005
Wed Apr 20 13:00:00 2005

The second string is the correct time both according to Perl and according to the JavaScript code.

Though I am using ActivePerl on Windows. That should not matter but it is possible a Linux Perl installation is giving different result. Try running the above code and seeing what your result is.

Re: unix time conversion wrong?
by Benno Schmid on 04/21/05 at 06:29:20

Ah, you use gmtime which prints out Greenwich Mean Time, which is shifted by two hours in my time zone (CEST). This explains the differences, though I would find it more natural to use local time.

Re: unix time conversion wrong?
by Robert Fogt on 04/21/05 at 13:13:09

The JavaScript version uses Universal Time Coordinated, which is almost the same thing as Greenwich Mean Time. It can differ by up to a second or two.  I do test it with GMT time though.

I can probably add a Local Time to the conversion page too. I think it might even be on my to-do list.  I will see what I can come up with.

Go Back | Archive Index


Did you find us useful?

Please consider supporting the site with a small donation.

click here for more information


BookMark Us

It may come in handy.

Check out our Conversion Software for Windows.

Can't find something?
Try searching.

Are you bored?
Try the Fun Stuff.

Was this site helpful?
Link to Us | Donate