Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Sitemap Date Format

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>

2 Answers

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

like image 187
Dunhamzzz Avatar answered Sep 07 '25 22:09

Dunhamzzz


To format the current timestamp in W3C Datetime encoding (as used in sitemap.xml files) use the following parameters.

echo date('Y-m-dTH:i:sP', time());

As of PHP5 you can also use the c format character to print the exact same string.

echo date('c',time());

These would both print out the following:

2009-04-03T11:49:00+01:00

SOURCE

like image 27
Erfan Safarpoor Avatar answered Sep 07 '25 21:09

Erfan Safarpoor