PHP daylight saving time detection

前端 未结 3 1689
暗喜
暗喜 2020-11-28 09:15

I need to send an email to users based wherever in the world at 9:00 am local time. The server is in the UK. What I can do is set up a time difference between each user and

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 09:41

    Do you need to know all the details of DST transition yourself? or do you just need to know when is 9:00 am in a given timezone?

    If it's the latter, PHP can use your operating system's timezone database to do that for you. The strtotime() function is remarkably good at "figuring out" what you mean:

    echo strtotime("today 9:00 am America/New_York");  // prints "1306501200"
    echo strtotime("today 9:00 am Europe/London");     // prints "1306483200"
    

    Just make sure you're using one of the PHP supported timezones.

提交回复
热议问题