<分区>
我检索的数据库日期格式是
$event_date='2013-01-20';
我想将这种格式转换成这样 2013-01-01
我试过了
echo date('M d, Y',$event_date)
//but it is printing wrong value "Jan 01, 1970"
并给出错误:注意 (8):遇到格式不正确的数值
如果有人能捕获请帮助我获得正确的值(value)
<分区>
我检索的数据库日期格式是
$event_date='2013-01-20';
我想将这种格式转换成这样 2013-01-01
我试过了
echo date('M d, Y',$event_date)
//but it is printing wrong value "Jan 01, 1970"
并给出错误:注意 (8):遇到格式不正确的数值
如果有人能捕获请帮助我获得正确的值(value)
最佳答案
您将需要使用 strtotime()
函数正确格式化日期,因为 date()
函数需要第二个参数是时间戳
echo date('M d, Y',strtotime($event_date));
来自文档
The function expects to be given a string containing an English date format and will try to parse that format into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 UTC), relative to the timestamp given in now, or the current time if now is not supplied.
现场工作样本 here
关于php - 在 PHP 中的日期格式之间转换给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22168770/