Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
检查印度的当前时间是否在php中的特定时间范围之间_Php_Date_Datetime - Fatal编程技术网

检查印度的当前时间是否在php中的特定时间范围之间

检查印度的当前时间是否在php中的特定时间范围之间,php,date,datetime,Php,Date,Datetime,我过去常常包含一些相关类来更改时区。但是,在PHP中如何不添加任何依赖项呢?如何检查印度的当前时间[例如]是否在特定时间范围内,并显示适当的消息 编辑bcoz的反对票:我自己提供了答案,这就是我发布这个问题的原因,以帮助将来的人。正如我在回答中所解释的,这就是为什么这个问题看起来没有任何努力/没有代码。 <?php date_default_timezone_set('Asia/Calcutta'); //echo date('Y-m-d h-i-s'); // prints 2015

我过去常常包含一些相关类来更改时区。但是,在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.";
}

?>