PHP daylight saving time detection

前端 未结 3 1692
暗喜
暗喜 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:56

    Changing my answer a bit: DateTimeZone::getTransitions looks like it will do what you need, provided you have PHP >= 5.2.

    From a comment in the documentation:

    getTransitions($theTime, $theTime); 
    
    // only one array should be returned into $transition. Now get the data: 
    $offset = $transition[0]['offset']; 
    $abbr = $transition[0]['abbr']; 
    ?>
    

    So here, all we need to do is pass in the timezone we want to check and we can know if that timezone is in DST/what the offset is. You'll then need to check the offset against GMT to see if you want to send your e-mail now, or not now.

提交回复
热议问题