Google Sitemap Date Format

前端 未结 10 1757
情书的邮戳
情书的邮戳 2021-02-12 09:35

I need date format for sitemaps in php.

How can i do that ?

Is this output right ?

2012-08-02EEST18:01:18+03:00


        
相关标签:
10条回答
  • 2021-02-12 10:08

    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

    0 讨论(0)
  • 2021-02-12 10:14

    with moment.js;

    moment().format('YYY-MM-DDTHH:mm:ssZ')
    
    0 讨论(0)
  • 2021-02-12 10:19

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

    0 讨论(0)
  • 2021-02-12 10:20

    You have a lot of formats to choose from. Using the c parameter with the date() function will get the recommended format for you.

    0 讨论(0)
  • 2021-02-12 10:22

    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.

    0 讨论(0)
  • 2021-02-12 10:23

    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
    
    0 讨论(0)
提交回复
热议问题