开发者

How to separate date and time using php from date time string?

How to convert this string

$parent = "2011-08-04 15:00:01";

to separate it into two strings:

$child1= "2011-08开发者_开发技巧-04";
$child2 = "12:00:01";

And then convert

$child1 to this format 8.4.2011 

and

$child2 to this format 15:00


$time = new DateTime("2011-08-04 15:00:01");
$date = $time->format('n.j.Y');
$time = $time->format('H:i');


$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


date('Y-m-d', strtotime( '2015-04-16 15:00:01' ) );

this will give you correct date format followed by mysql i.e 2015-04-16 03:54:17

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜