I need date format for sitemaps in php.
How can i do that ?
Is this output right ?
2012-08-02EEST18:01:18+03:00
delete "EES" Mine is like this 2013-12-26T19:00:00-05:00 and it works http://www.industry-automation-parts.com/1_e_0_sitemap.xml
with moment.js;
moment().format('YYY-MM-DDTHH:mm:ssZ')
If you have the timestamp you can format the date correctly like this:
<lastmod><?php echo date('c', $timestamp); ?></lastmod>
Time stamp could be time()
(for current time) or some other method of fetching a unix tiemstamp like strtotime()
You have a lot of formats to choose from. Using the c
parameter with the date() function will get the recommended format for you.
Your getting this output because you used the old recommended timestamp string of
Y-m-dTH:i:sP.
However, what you need is
Y-m-d\TH:i:sP
This single back slash will make the difference. At some point a capital T became a special character in PHP signifying timecode, so if you don't escape the T you will get exactly what your reporting.
To convert from a MySQL's datetime format to the one needed for lastmod in sitemaps, just use the PHP code below.
$lastmod = '2012-11-28 10:53:17'; //MySQL datetime format
$datetime = new DateTime($lastmod);
$result = $datetime->format('Y-m-d\TH:i:sP');
echo $result; //2012-11-28T10:53:17+01:00