How to get XML sitemap date format in PHP
Sitemap is important file and route for SEO tools. The sitemap should be standard XML format. Sitemap contains few xml tags which should be in proper format. You can find more details about sitemap at this article.
The <lastmod>
tag which shows date of last modification of the file. This date should be in W3C Datetime format.
To format the standard date format in PHP,use the below parameters in date()
function.
<?php
echo date('Y-m-dTH:i:sP', time());
As of PHP5 you can also use the c character to print the exact same string.
<?php
echo date('c',time());
These both code will print date as per sitemap format.
2021-03-28T14:25:59+00:00
Copyright 2022 HackTheStuff