PHP вставляет поздно через блоки времени

Привет я пытаюсь сделать посещаемость времени на основе графика, и если нет, код заблокирует меня, я так думаю?

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

Решение

Я думаю, что вы должны проверить время UTC и разницу во времени вашей системы. Код для проверки ниже

<?php
$d = new DateTime();
$dtz = ($d->getOffset())/3600;//returnt he difference between utc and local time
timeToSeconds($dtz);

function timeToSeconds($dtz)
{
$timeExploded = explode(':', $dtz);

if (isset($timeExploded[2])) {
return $timeExploded[0] * 3600 + $timeExploded[1] * 60 + $timeExploded[2];//ccalculate it into seconds

}
$val=$timeExploded[0] * 3600 + $timeExploded[1] * 60;//return the seonds
echo "Actual difference between utc and timestamp: ". $dtz."<br />";//the time difference in hours
echo "The total second is: ".$val."<br />";//time difference in seconds
$hours = floor($val / 3600);
$mins = floor($val / 60 % 60);
$secs = floor($val % 60);
$timeFormat = sprintf('%02d:%02d:%02d', $hours, $mins, $secs);//convert seconds into H:i:s
echo "After seconds to time ".$timeFormat."<br />";
$dda=date("h:i:sa");//return the current timestamp
echo "The current time is " . $dda."<br/>";
$convert_current=strtotime($dda);//convert current timestamp
$convert_utc=strtotime($timeFormat);//convert utc time
echo "Convertion on current time: ".$convert_current."<br />";
echo "Convertion on utc: ".$convert_utc."<br />";
$minus=$convert_current-$convert_utc;//differentiate two time
echo "The two difference in seconds: ".$minus."<br />";
$hours = floor($minus / 3600);
$mins = floor($minus / 60 % 60);
$secs = floor($minus % 60);
$correct = sprintf('%02d:%02d:%02d', $hours, $mins, $secs);//converting again it into H:i:s
echo "UTC time: ".$correct."<br />";
}
?>

В них вы должны проанализировать с часовым поясом по умолчанию вы были приняты с текущим временем.

1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector