开发者

Convert date/time (PHP) [duplicate]

开发者 https://www.devze.com 2022-12-22 22:04 出处:网络
This question already has ans开发者_JAVA技巧wers here: Convert one date format into another in PHP
This question already has ans开发者_JAVA技巧wers here: Convert one date format into another in PHP (17 answers) Closed 5 years ago.

Is there an easy way to convert date and time like this:

Sun, 14 Mar 2010 09:00:00 GMT

To this format:

20100306T153626

in PHP


Use the strtotime and date functions.

$result = date('Ymd\THis', strtotime('Sun, 14 Mar 2010 09:00:00 GMT'));

The “T” has to be escaped, because it has special meaning (timezone abbreviation).


You want the date function. The format string for 20100306T153626 is:

YmdTHis

i.e.

date("Ymd\THis");

for the current date/time. If you want to use your own time, you'll need it as a Unix timestamp, which you can use the mktime function for that.

0

精彩评论

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