Sitemap lastmod date in Javascript
Asked Answered
L

1

10

I need to the date format that is shown in <lastmod></lastmod> tags in sitemap.xml. How can I achieve that?

Output like:

<lastmod>2016-01-21EEST18:01:18+03:00</lastmod>

Where 'EEST' is probably timezone offset.

I have seen this question and the answers in php:

Google Sitemap Date Format

but don't know how to achieve it in Javascript,

Thanks.

EDIT: the question is not duplicate, since I need the correct time format in JavaScript for this.

Lustrous answered 21/9, 2017 at 8:19 Comment(1)
No it is not a duplicate, as I need to know the timeformat for this..Lustrous
A
22

The lastmod tag uses YYYY-MM-DDThh:mmTZD format, where TZD is the time zone offset. The W3 date and time format gives you 3 options for how to do the TZD: (Z or +hh:mm or -hh:mm)

This means that in javascript you can just use

const date = new Date().toISOString();

and it'll look like 2017-11-15T11:18:17.266Z, which is correct for a sitemap lastmod.

Achromatism answered 15/11, 2017 at 11:24 Comment(1)
How can we show in +hh:mm or -hh:mm instead of Z? Official documentation uses +hh:mm format. google.com/sitemaps/protocol.htmlMartita

© 2022 - 2024 — McMap. All rights reserved.