douxuanyi2813 2015-08-05 11:15
浏览 34
已采纳

PHP中的日期函数问题[重复]

This question already has an answer here:

I have one issue with date function below i have put my all code. Please check. I have used jQuery calender in my joomla component

 echo $data['startpublish'];

    $data['startpublish'] = date('Y-m-d', strtotime($data['startpublish']));
    echo "?>>>>>>>>>>>".$data['startpublish'];

    exit;

I have store my date into mm-dd-yy format. When i store 01-02-2015 then it will store data in DB in (Y-m-d) format and when i store 01-28-2015 (28 Janvary) then it will convert into 1970-01-01.

Please let me know what the issue . I have added both screenshot as well.

issue SS : http://prntscr.com/812w0c

correct SS : http://prntscr.com/812xbj

</div>
  • 写回答

1条回答 默认 最新

  • dran0703 2015-08-05 11:30
    关注

    This is a strtotime quirk to do with the text date representation and the American illogical way of saying/writing dates used in the conversion having either - or / or . seperators.

    Quote from the PHP Manual, now why did I go there for information I wonder.

    Note:

    Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed.

    So to make an american date format 01-28-2015 store properly you have to convert it to have / seperators like so for example

    $data['startpublish'] = str_replace('-','/', $data['startpublish']);
    
    $data['startpublish'] = date('Y-m-d', strtotime($data['startpublish']));
    echo "?>>>>>>>>>>>".$data['startpublish'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集