简体   繁体   中英

php strtotime with a future datetime returns a timestamp less than current timestamp

I am running php on my server. The docs for the strtotime function says that it will try to parse the datestring into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 UTC).

So my test scenario is:

Timestamp for string "2018-05-15 14:30" : 1526387400 => strtotime("2018-05-15 14:30")

Current timestamp as per GMT 2018-05-15 13:26 : 1526390790 => time()

Here i expected the timestamp at 14:30 to be greater the 13:26. But inspite of a future datestring, the value is less than the current timestamp.

The server that i am testing this operates on GMT+2 timezone = date('Z') => 7200. I was assuming as per the docs, the strtotime function to return second elapsed since epoch without taking the timezone offset into account. I am not sure if the timezone offset is messing up the numbers.

Any insight into this would be very helpful.

From strtotime() manual

Each parameter of this function uses the default time zone unless a time zone is specified in that parameter. Be careful not to use different time zones in each parameter unless that is intended.

From time() manual

Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).

So your strtotime() is in GMT+2 and time() in GMT

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM