douqi3913 2014-02-12 21:32
浏览 49
已采纳

strtotime()没有返回适当的时间

I'm having trouble getting strtotime() to work correctly.

For starters, Here's my goal: I'm trying to set it up that you can only create an article every 5 minutes.

To accomplish this I've got

    strtotime('5 minutes')<strtotime($lastcreate)

this code ^^ in my file.

   <?php
        echo '<ul><li>' . strtotime($lastcreate) . '</li>';
        echo '<li>' . strtotime("now") . '</li></ul>'; ?>

Outputs:
1392203323
1392228579

$lastcreate is stored in my database as now()

When i use this code to call it. The numbers differ by like 7 hours.

Does anybody know why it does this and/or a better way to go about doing this?

  • 写回答

3条回答 默认 最新

  • dony113407 2014-02-12 22:03
    关注

    Here is what you are looking for, ways to set your timezone to match in both PHP and MySQL and the correct comparison.

    PHP

    date_default_timezone_set('America/New_York');

    MySQL Query Run Before Your Query

    SET time_zone = 'US/Eastern'

    Your PHP Comparison

    if(strtotime('now') >= strtotime($lastcreate . ' +5 minutes')){
        // its been more then 5 minutes since the last post
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构