Google Sitemap Date Format

前端 未结 10 1745
情书的邮戳
情书的邮戳 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:32

    According to Google, he value is an optional field that, if provided, must be formatted as

    YYYY-MM-DDThh:mmTZD 
    

    The default export of an SQL datetime is dependent on the language setting for your server, and may include spaces and characterized TZD such as:

    2014-09-19 10:33:05 UTC
    

    The W3 specify that TZD can be formatted in any of three options

    TZD = time zone designator (Z or +hh:mm or -hh:mm)

    Any spaces from your default formatting must be stripped; the character 'T' must be inserted before time, and the TZD must match one of the supported types.

    Therefore to format the current timestamp, 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());
    

提交回复
热议问题