如何将这个来自数据库字符串格式化成更具可读性的内容。
2012-04-06T10:55:58-07:00
我想要m-y格式的。我试过了
$date = date('m-y',strtotime('2012-04-06T10:55:58-07:00'));我被难住了。
谢谢!
发布于 2012-06-07 07:25:38
如果时区没有意义,你可以像这样把它切掉:
$dbDateString = '2012-04-26T10:55:58-07:00';
$dateString = substr($dbDateString, 0, 10);
$date = date('m-y',strtotime($dateString);或者你可以选择便宜的路线:
$dbDateString = '2012-04-26T10:55:58-07:00';
$year = substr($dbDateString, 0, 4);
$month = substr($dbDateString, 5, 2);发布于 2012-06-07 07:14:44
查看:How do I convert an ISO8601 date to another format in PHP?
他们提供的解决方案是:
$date = '2011-09-02T18:00:00';
$time = strtotime($date);
$fixed = date('l, F jS Y \at g:ia', $time); // 'a' is escaped as it's a format char.https://stackoverflow.com/questions/10923502
复制相似问题