How to convert date from one format to another in Php

陌路散爱 提交于 2019-12-25 03:48:05

问题


How to convert date from "2011-08-01 04:01:45" to "Mon, 01 Aug 2011 05:37:45 -0400" in Php

Thanks a lot...


回答1:


$newDate = date('r', strtotime('2011-08-01 04:01:45'));



回答2:


use the strtotime function in php to parse the date string and then the date function to print it in whatever format you'd like.

<?php

$orig = "2011-08-01 04:01:45";

$timestamp = strtotime($orig);

echo date("D, d M Y H:i:s O",$timestamp);
?>



回答3:


I know that this isn't going to solve your problem but a really fast method of using dates and information is to store the time using a unix time stamp. This is an integer value of seconds counting from the time (1970 -1 second).

It will allow you to format dates in a much simpler manner using something like:

<?php date('d-m-Y', $unixTimeStamp); ?>

This method is also much faster when it comes to comparing times.



来源:https://stackoverflow.com/questions/6963848/how-to-convert-date-from-one-format-to-another-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!