Alright, I can't seem to figure out what is going on, so I have decided to ask you guys. In PHP I am grabbing the UTC timestamp using this code:
date_default_timezone_set("UTC");
time()
This will for example give me 1331065202
Then I have this code in Java to get me the UTC timestamp:
long timestamp = System.currentTimeMillis() / 1000;
This will for example give me 1331093502
Why are the 2 times so different? Shouldn't they both be in UTC Timezone or am I doing something wrong? I am hosted on a VPS and these scrips are on 2 different servers so could it be something on the server side and if so, what can I do?
Given that the two values are wildly different (not even an integer number of hours), I'd say the clock on one of the machines is wrong. (I'm assuming you took the two timestamps at pretty much the same time.)
Those timestamps are:
Given that it's not March 27th in GMT, it looks like the clock on the Java machine is simply set incorrectly.
If it's a true VPS that you have complete control over, you should look into using NTP or something similar to keep the servers' clocks correct.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With