donglian4464 2015-12-10 18:39
浏览 24
已采纳

PHP日期转换为不正确的格式[重复]

This question already has an answer here:

I am posting data with dates in this format:

06/11/2015

i then use the below function to change the date format to insert into a database:

ChangeDateFormat('06/11/2015', 'Y-m-d');

date_default_timezone_set('Europe/London');
if(!function_exists("ChangeDateFormat")) {
    function ChangeDateFormat($date = '', $format = '') {
        if($date == '' or $date == '0000-00-00' or $date == '0000-00-00 00:00:00') {
            return '-';
        } else {
            return date($format, strtotime($date));
        }
    }
}

but its inserting into the following format:

2015-06-11 whereas it should be 2015-11-06

</div>
  • 写回答

1条回答 默认 最新

  • drxyaox153896 2015-12-10 18:49
    关注

    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. If, however, the year is given in a two digit format and the separator is a dash (-, the date string is parsed as y-m-d. To avoid potential ambiguity, it's best to use ISO 8601 (YYYY-MM-DD) dates or DateTime::createFromFormat() when possible. link

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题