嗨我试图根据时间表进行考勤,如果不是代码会阻止我,我会这样想吗?
date_default_timezone_set('Asia/Hong_Kong');
$now = new DateTime();
$mysched = new DateTime("16:00");
// time sessions
// 7pm / 19:00
if ($now -> format ("H:i") > "19:00") {
// getting my late
$deadline = DateTime::createFromFormat("H:i", "19:15");
$diff = $now->diff($deadline);
echo "You're ".$diff->i." minutes late";
}
// 4pm / 16:00
else if ($now -> format ("H:i") > "16:00") {
$deadline = DateTime::createFromFormat("H:i", "16:15");
$diff = $now->diff($deadline);
echo "You're ".$diff->i." minutes late";
}
// 1pm :13:00
if ($now -> format ("H:i") > "13:00") {
$deadline = DateTime::createFromFormat("H:i", "13:15");
$diff = $now->diff($deadline);
echo "You're ".$diff->i." minutes late";
}
else {
// block if im trying to log at 1pm
}
// continue to inserting late to db....
所以问题是我在哪里将块代码段添加到代码中?
答案 0 :(得分:1)
我认为你必须检查UTC时间和你的系统时差。检查的代码在下面
public void GetNewMemes(string subReddit, int count)
{
SetSelectedSubreddit(subReddit);
memesAtATime = count;
subJSON = null;
var enumerator = GetJSONFromSelectedSubreddit();
while (enumerator.MoveNext());
enumerator = LoadNewMemes();
while (enumerator.MoveNext());
}
在这些中,您必须使用当前时间拍摄的默认时区进行分析。