Google Sitemap Date Format

2020-06-08 02:35发布

I need date format for sitemaps in php.

How can i do that ?

Is this output right ?

<lastmod>2012-08-02EEST18:01:18+03:00</lastmod>

10条回答
淡お忘
2楼-- · 2020-06-08 03:07

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

查看更多
劳资没心,怎么记你
3楼-- · 2020-06-08 03:08

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()

查看更多
4楼-- · 2020-06-08 03:12

Actually, there are 2 approaches to this.

The first approach is to set a valid date for XML sitemap which includes the "C" char which gave the value: (2019-06-03T17:30:21-05:00). Test it here

<lastmod>'.date('c', strtotime($row['date'])).'</lastmod>

The 2nd approach is to set a valid date for RSS sitemap which includes the "r" char which gave the value: (2019-03-07T17:55:44+00:00).

<pubDate>'.date('r', strtotime($row['date'])).'</pubDate>

Hope this helps you. Thanks

查看更多
Explosion°爆炸
5楼-- · 2020-06-08 03:13

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
查看更多
神经病院院长
6楼-- · 2020-06-08 03:15

with moment.js;

moment().format('YYY-MM-DDTHH:mm:ssZ')
查看更多
【Aperson】
7楼-- · 2020-06-08 03:27

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.

查看更多
登录 后发表回答