脚本宝典收集整理的这篇文章主要介绍了计算哪些时区在PHP上具有特定的当前本地时间,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
// Target local time in hours (6:00 PM = 18:00) $targetHour = 18; // Get timestamp of nearest quarter-hour. // (Assuming this is being run by cron on-the-quarter-hour by server time) date_default_timezone_set('GMT'); $currentHourTimestamp = (round(time() / 900) * 900); // Calculate offset in hours to target hour $targetDateTime = new dateTime('@' . $currentHourTimestamp,new DateTimeZone('GMT')); $targetDateTime->setTime($targetHour,0); $targetOffset = $targetDateTime->getTimestamp() - $currentHourTimestamp; // You can get this From the database wITh a // 'SELECT DISTINCT timezones From users' query or similar $timezoneSUSEd = array('America/Los_Angeles','America/Phoenix','EuroPE/Budapest','Europe/Dublin'); $matchingTimezones = array(); foreach($timezonesUsed as $localTimezone) { // throws an Exception if timezone is not recognized $localDateTimezone = new DateTimeZone($localTimezone); $localOffset = $localDateTimezone->getOffset($targetDateTime); if($localOffset == $targetOffset) $matchingTimezones[] = $localTimezone; } // Now send emails to users in database with timezones in $matchingTimezones
编辑:根据Catcall的建议使用改编脚本来使用四分之一小时.
以上是脚本宝典为你收集整理的计算哪些时区在PHP上具有特定的当前本地时间全部内容,希望文章能够帮你解决计算哪些时区在PHP上具有特定的当前本地时间所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。