如何转换此字符串
$parent = "2011-08-04 15:00:01";
将它分成两个字符串:
$child1= "2011-08-04";
$child2 = "12:00:01";
然后转换
$child1 to this format 8.4.2011
和
$child2 to this format 15:00
答案 0 :(得分:7)
$parent = '2011-08-04 15:00:01';
$timestamp = strtotime($parent);
$child1 = date('n.j.Y', $timestamp); // d.m.YYYY
$child2 = date('H:i', $timestamp); // HH:ss
答案 1 :(得分:6)
$time = new DateTime("2011-08-04 15:00:01");
$date = $time->format('n.j.Y');
$time = $time->format('H:i');
答案 2 :(得分:0)
date('Y-m-d', strtotime( '2015-04-16 15:00:01' ) );
这将为您提供正确的日期格式,后跟mysql 即2015-04-16 03:54:17