开发者

Using PHP to convert from one date format to another

I'm looking to convert a date from one format to another.

This is my current date format:

2011-08-15 15:35:58

and I need to convert it into:

Mon, 15/08/2011 15:35

I can quite easily create this by cutting the last 3 characters from the time and then using str_replace to change '-' into开发者_运维百科 '/' and so on, but I was wondering if there is there is a way to do this automatically using the date() function or something similar. I am also not sure how to generate the day of the week e.g. 'Mon', 'Tues' etc.

Hope someone can help. Thanks.


This can be done easily using a combination of date() and strtotime():

$newDate = date('D, d/m/Y H:i', strtotime($oldDate));


Use strtotime and date functions:

$d = strtotime("2011-08-15 15:35:58");

var_dump(date( 'D, d/n/Y H:i',$d));


This code work fine:

<?

$time = strtotime("2011-08-15 15:35:58");
echo date("D, d/m/y H:m", $time);

But be carefull, strtotime depends on timezone settings.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜