Seems I don't quite understand much the function strtotime. My case is I would like to compare the current time (now) with a specific time on specific timezone
For example the specific time is "this Monday at 14:00:00" at the timezone "America/New_York":
$specificTime = strtotime("monday this week 14:00:00 America/New_York");
My current code is:
$now = strtotime("now America/New_York");
if ($now > $specificTime) {
//do something
}
But I have figured it out that $now above is 6 hours ahead with current time. The number 6 I guess from offset -05:00 of America/New_York, plus with 1 hour daylight saving.
it should remove timezone out of $now, it will work correctly:
$now = strtotime("now");
if ($now > $specificTime) {
//do something
}
Could someone give the explain why strtotime("now America/New_York") is 6 hours ahead with strtotime("now), why they are not equivalent? really confused.
P.S: I am on GMT+07:00.
nowandnow America/New_Yorkto be equivalent when your machine is in a completely different time zone? Also,strtotimeis not magic. I'd never want to rely on it getting "monday this week 14:00:00 America/New_York" correct. Have you tried usingDateTime, explicitly setting timezones and doing a little bit of date math? - decezestrtotimereturn a timestamp and the timestamp does not depend on the timezone. So simple thinking is "now" in here is also equivalent with "now" in any place in the world. My point is why the difference is 6 hours ahead? - cuonglenowmeans the current time. Simultaneously if you are sleeping in Europenowis a different time (but the same instant). - Jim