Php 计算一天中剩余的分钟数
我试图计算一天还剩多少分钟。我以为我有答案,但数字看起来有点奇怪 我的代码:Php 计算一天中剩余的分钟数,php,Php,我试图计算一天还剩多少分钟。我以为我有答案,但数字看起来有点奇怪 我的代码: date_default_timezone_set('Europe/London'); $sTime = date("d-m-Y H:i:s"); echo 'The time is: ' . $sTime."<br>"; $NowTime = date("H:i"); echo $NowTime."<br>"; $start = strtotime($NowTime); $stop
date_default_timezone_set('Europe/London');
$sTime = date("d-m-Y H:i:s");
echo 'The time is: ' . $sTime."<br>";
$NowTime = date("H:i");
echo $NowTime."<br>";
$start = strtotime($NowTime);
$stop = strtotime("23:59");
$diff = ($stop - $start); //Diff in seconds
echo "start ". $start."<br>";
echo "stop " .$stop."<br>";
echo "diff " .$diff."<br>";
$minutes = $diff / 60;
echo "minutes ". $minutes."<br>";
$hours = $minutes / 60;
echo "hours " .$hours."<br>";
date\u default\u timezone\u set(“欧洲/伦敦”);
$sTime=日期(“d-m-Y H:i:s”);
回显“时间是:”$时间“
”;
$NowTime=日期(“H:i”);
echo$NowTime.“
”;
$start=strottime($NowTime);
$stop=strottime(“23:59”);
$diff=($stop-$start)//秒差
回显“开始”$开始“
”;
回显“停止”。$stop。“
”;
回声“diff.”$diff.“
”;
$minutes=$diff/60;
回音“分钟”$分钟“
”;
$hours=$minutes/60;
回显“小时”。$hours.“
”;
输出:
15:24
开始1446909840
停止1446940740
diff 30900
H:M 08:35:00
第515分钟
小时8:58333
问题:如何将小时数“8.58333”转换为8.xx分钟
非常感谢您的时间。如果您可以访问
DateTime
类,您可以非常轻松地完成此操作
$timezone=new DateTimeZone( 'Europe/London' );
$now=new DateTime( 'now', $timezone );
$midnight=new DateTime( date('Y-m-d H:i:s', strtotime('11.59pm') ), $timezone );
$diff = $now->diff( $midnight );
$mins=( intval( $diff->format('%h') ) * 60 ) + intval( $diff->format('%i') );
echo $diff->format('%h hours %i minutes %s seconds').'<br />Minutes left until midnight: '.$mins;
$timezone=新日期时区(“欧洲/伦敦”);
$now=新的日期时间('now',$timezone);
$midnight=新日期时间(日期('Y-m-d H:i:s',标准时间('11.59 pm')),$timezone);
$diff=$now->diff($midnight);
$mins=(intval($diff->format('%h'))*60)+intval($diff->format('%i'));
echo$diff->格式(“%h小时%i分钟%s秒”)。
离午夜还有几分钟:'.$min;
我有一个按天、小时、分钟或秒计算时间差的fx。输入日期并返回结果。Pos或负面结果取决于您输入的方式
$ApptHourTillMidnight= (GetTimeDiff( date('Y-m-d 23:59:59'),date('Y-m-d H:i:s'),'m') ); //get minutes until midnight
function GetSeconds($time){
$seconds = strtotime($time); return $seconds;
}
}
function GetTimeDiff($time1,$time2,$type){
$s= GetSeconds($time1);
$e= GetSeconds($time2);
switch (strtolower($type)) {
case "s";
return ($s - $e);
case "m";
return (($s - $e) / 60);
case "h";
return ((($s - $e) / 60)/60);
case "d";
return (((($s - $e) / 60)/60)/24);
return FALSE; //wrong type
}