시간대를 변경하기 위해 일부 종속 클래스를 포함했습니다. 그러나 종속성을 추가하지 않고 PHP에서 어떻게 할 수 있습니까? 인도의 현재 시간 [예 :]이 특정 시간 범위 사이인지 확인하고 적절한 메시지를 표시하는 방법
다운 보트의 bcoz 편집 : 나 자신이 이에 대한 답변을 제공했고, 이것이 내가이 질문을 게시 한 이유입니다. 그것이 내가 내 대답에서 설명한 것처럼 아무런 노력이나 코드가없는 것처럼 보이는 이유입니다.
<?php
date_default_timezone_set('Asia/Calcutta');
//echo date('Y-m-d h-i-s'); // prints 2015-08-25
$currentTime = time();
// if you want to check the hour only. This can also be checked via mktime(16, 0, 0)
if (((int) date('H', $currentTime)) >= 16) {
echo "current time is greater than 4pm";
} else {
echo "current time is less than 4 pm";
}
// if you want to check the hour and minute together
if($currentTime > mktime(16, 29, 0)) {
echo " We're sorry, This service is available only before 4pm";
} else {
echo "";
}
// if you want to check the hour and minute together in a range
if($currentTime < mktime(6, 0, 0) || $currentTime > mktime(16, 30, 0)) {
echo " We're sorry, This service is available only between 6 AM and 4:30 PM";
} else {
echo "";
}
// check if current date/time is greater than a particular date/time
if (new DateTime() > new DateTime("2015-08-26 16:00:00")) {
# current time is greater than 2015-08-25 16:00:00
echo "This coupon is expired.";
}
?>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다