Convert date/time (PHP) [duplicate]
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.
精彩评论