English 中文(简体)
添加两个时间值并与其他时间比较
原标题:add two time values and comparing with other time

i 有两个时间值, 包括起始时间= 23: 00: 00 和估计时间= 00: 45: 00 现在我想添加起始时间和估计时间, 并将其存储在变量中, 我就是这样做的 。

$add = abs(strtotime($starttime) + strtotime($estimationtime));

现在我必须比较一个新的时间, 表示当前时间或其它时间间隔( 23: 50: 00)

if($time >=$starttime && $time <=$add)
{
$message=array("message"=>"there is an appointment");
}

如果我回回 $add I 没有得到正确的格式, 它显示 267575756700 pls 帮助我解决这个问题

最佳回答

如果您想要以可读形式回响您的 $add 变量, 您必须先将其格式化 。

echo(date("H:i:s", $add));
问题回答

strtotime () 返回一个时间戳, 这是 Jan 1/ 1970 之后的秒数。 您无法将它与格式化的时间值比较 - 它只是一个整数 。

所以基本上,你做的相当于:

$add = 1 + 2; // 3

if (3 >=  23:50:00 ) ...

如果您想要比较时间值作为时间戳, 您就必须将所有东西转换为时间戳。 或者, 您可以使用 < a href=" http:// php. net/ datetime" rel= "nofollow" > DateTime 物件 , 这将自动处理很多这类事情 。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签