Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sitemap lastmod date in Javascript

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.

like image 363
stormec Avatar asked Sep 21 '17 08:09

stormec


1 Answers

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.

like image 170
Carasel Avatar answered Oct 02 '22 17:10

Carasel