XML Sitemap Date Format In PHP

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

Comments

hi, new to the site, thanks.
Permalink
Thanks
Permalink
Thanks.. you solved my problem
Permalink
so simple. I finally find clear one here .. nice contribution
Permalink
Brilliant! Simple! Works! Thanks so much
Permalink
thannks for share :) awesome post..
Permalink

I think it's wiser to use the following parameters:

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

Because the first method could give a different format (2020-08-30CEST22:28:28+02:00)

Permalink

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
1 + 5 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.