【问题标题】:Bad php date(); when using EasyPHP错误的 php 日期();使用 EasyPHP 时
【发布时间】:2023-03-14 04:58:01
【问题描述】:

我正在使用 EasyPHP 和 Codeigniter 来开发我的博客,因为我,可能是大多数人,按发布日期/时间排序 cmets、帖子等,我在排序时遇到了一些麻烦,因为EasyPHP 不知何故弄错了时间,我的意思是以前的条目是 2013-11-09 03:11:40,最近发布的是 2013-11-09 03:11:20。为了在我进行查询之前获得时间,我这样做:

date('Y-m-d h:m:s');

执行的代码示例:

public function new_comment()
    {
        $text = $this->input->post('text');
        $p_id = $this->input->post('p_id');
        $u_id = $this->input->post('u_id');
        $time = date('Y-m-d h:m:s');
        $username = $this->input->post('username');

        $data = array(
            'user_id' => $u_id,
            'post_id' => $p_id,
            'text' => $text,
            'time' => $time,    
            'username' => $username
        );

        if($this->db->insert('comments', $data))
        {
            $back['sql'] = 'Query successful';
            $back['next'] = '1';
            $back['c_id'] = $this->db->insert_id();
            $back['time'] = $time;
        }
        else
        {
            $back['sql'] = 'Something went wrong';
            $back['next'] = 0;
        }

        print json_encode($back);
    }

我怀疑这是一个与代码相关的问题,可能这只是 localhost 是一个 derp。为什么这是个问题?我正在测试一些花哨的 AJAX 加载 cmets 而没有刷新,我无法测试它,因为日期不好。有人遇到过这个问题吗?

【问题讨论】:

    标签: php codeigniter date localhost easyphp


    【解决方案1】:

    您使用了两次“m”,第一次应该表示“月”,第二次表示“分钟” - 它不是。

    正确的格式字符串是"Y-m-d H:i:s"。 “分钟”的格式标识符是“i”。

    【讨论】:

    • f**king 由行业“专业人士”编写的教程。 +1,谢谢伙计。
    • @Syfor:教程?没有比manual 自己更好的教程了。
    • @Glavić 我知道,我用的是手册,但是这段代码虽然有点修改,但是是很久以前一起学习PHP和CodeIgniter的时候,所以我用了一些教程,或者google了一下解决方案。当然不是网上的所有东西都是真的,只是没想到错误会出现在这里。
    猜你喜欢
    • 1970-01-01
    • 2012-01-11
    • 2020-03-24
    • 1970-01-01
    • 1970-01-01
    • 2016-09-30
    • 1970-01-01
    • 2012-12-01
    • 1970-01-01
    相关资源
    最近更新 更多