新解决方案见下文!
如果您知道时区,您可以简单地将其“添加”到您的时间。
例如:
服务器时间:01/01/01 00:00 用户想要的时间:01/01/01 01:00 用户的时区:GMT - 5
只需获取时间 (01/01/01 01:00) 并添加 +5 => 01/01/01 06:00
所以:您的脚本需要在 01/01/01 06:00 执行
(在需要时转换为时间戳)
添加了一个小 php 来演示
<?php
$servertime = time(); //timestamp of 01/01/01 00:00
$usertime = "01/01/01 06:00";//database
$userUTC = "-5";//database
strreplace($userUTC, "-", "+";
$replacetext = $userUTC . " days";
$usertime = strtotime($replacetext, $usertime);//now usertime is in your local timezone
$crontime = date("d/m/Y H:i");//the time you want the script to be executed
?>
我只是假设时区保存为“-5”而不是欧洲/阿姆斯特丹如果我错了就告诉我。
编辑 14:37
我认为这可能是一个更好的解决方案!
<?php
$usertime = "01/01/01 06:00";
$userUTC = "-5";
$userdate = $usertime . " " . $userUTC;
$usertimestamp = strtotime($userdate);//now you have the timestamp with correct timezone
$crontime = date("d/m/Y H:i", $usertimestamp);//formatted to the right date
echo $crontime;
?>
编辑:25-07-2013 14:26
适合您的数据库的新解决方案:
<?php
$usertime = "01/01/01 06:00";
$userUTC = "Pacific/Auckland";//get from database
$userdate = $usertime . " " . $userUTC;
$usertimestamp = strtotime($userdate);//now you have the timestamp with correct timezone
$crontime = date("d/m/Y H:i", $usertimestamp);//formatted to the right date
echo $crontime;
?>