我如何将datetime转换为unix时间戳并将其与php中的其他时间戳进行比较?
I have one page in that I have two textboxes where user will enter unix timestamp and datetime, I have to compare that both timestamp and datetime but in php the timezone giving different timestamp as per time zone so the code doesn't working in all places where time zones are different.
Please help on this I had used..
strtotime(),mktime(),getTimestamp()in php,
also used my sql for this..
SELECT UNIX_TIMESTAMP()but all are giving different time stamps.
$sql = "SELECT UNIX_TIMESTAMP('date time from text box') as timeStampfromdb";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
$timeStampFromDateTime = $row["timeStampfromdb"];
}
if($timeStampFromDateTime == timestamp textbox value)
{
matched
}
else
{
not matched
}
我有一个页面,我有两个文本框,用户将输入unix时间戳和日期时间,我必须比较一下 时间戳和日期时间,但在php中,时区根据时区给出不同的时间戳,因此代码在时区不同的所有地方都不起作用。 p>
请帮助我这个我用过的 .. p>
p>
strtotime(),mktime(),getTimestamp() pre>在php中,也用我的sql for 这个.. p>
p>
SELECT UNIX_TIMESTAMP() pre>但所有都给出了不同的时间戳。$ sql = “SELECT UNIX_TIMESTAMP('来自文本框的日期时间')as timeStampfromdb”; $ result = mysql_query($ sql); while($ row = mysql_fetch_array($ result)) { $ timeStampFromDateTime = $ row [“timeStampfromdb”]; } if($ timeStampFromDateTime == timestamp textbox value) { 匹配 } else { 不匹配 } code> pre> div>
You can set php timezone in php.ini file, for GMT you need "GMT".
You can also try in your code:
echo date('Y-m-d H:i:s T', time()) . "<br>
";
date_default_timezone_set('GMT');
echo date('Y-m-d H:i:s T', time()) . "<br>
";
time() should return the current unix timestamp.
If you are working with dates and times across time zones you should work with everything in GMT to avoid time zone issues. If you need to display a date and time at some point that is the place to do any time zone conversion that may be necessary.