dpik71879
2016-01-09 12:43
浏览 68

我如何将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
            }

图片转代码服务由CSDN问答提供 功能建议

我有一个页面,我有两个文本框,用户将输入unix时间戳和日期时间,我必须比较一下 时间戳和日期时间,但在php中,时区根据时区给出不同的时间戳,因此代码在时区不同的所有地方都不起作用。

请帮助我这个我用过的 ..

 strtotime(),mktime(),getTimestamp()在php中,
 
 

也用我的sql for 这个..

 SELECT UNIX_TIMESTAMP()但所有都给出了不同的时间戳。
 
 
  $ 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 
 {
不匹配
} 
   
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doupuzhimuhan9216 2016-01-09 12:52
    已采纳

    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.

    点赞 评论
  • dongshan9619 2016-01-09 12:54

    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.

    点赞 评论

相关推荐 更多相似问题