Reputation: 15052
I found out that these two returns different numbers - but both should give a timestamp.
strtotime( date("Y-m-d h:i:s") ); //currently 1447570497
time(); //currently 1447613697
The difference is exactly 12 hours (43200 seconds), also same thing happens for:
(new DateTime( date("Y-m-d h:i:s") ))->getTimestamp(); //acts like strtotime+date
(new DateTime("now"))->getTimestamp(); //acts like time()
Why is this happening? (Since it's 12 hours it is probably not daylight-saving time issue)
Is it something with 24 vs 12 hours - modes?
Upvotes: 1
Views: 89
Reputation: 219894
You need to use H
in date()
to get the correct time after 12pm. Otherwise you will be off by 1 - 12 hours.
strtotime( date("Y-m-d H:i:s") ); //currently 1447570497
Upvotes: 5