javascript - Javascript 中的站点地图 lastmod 日期

标签 javascript php html xml sitemap

我需要 <lastmod></lastmod> 中显示的日期格式sitemap.xml 中的标签。我怎样才能做到这一点?

输出如下:

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

其中“EEST”可能是时区偏移量。

我在 php 中看到了这个问题和答案:

Google Sitemap Date Format

但不知道如何用Javascript实现,

谢谢。

编辑:问题不重复,因为我需要 JavaScript 中的正确时间格式。

最佳答案

lastmod 标签使用YYYY-MM-DDThh:mmTZD 格式,其中TZD 是时区偏移量。 W3 date and time format为您提供了 3 个选项来执行 TZD:(Z 或 +hh:mm 或 -hh:mm)

这意味着在 javascript 中你可以直接使用

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

它看起来像 2017-11-15T11:18:17.266Z,这对于站点地图 lastmod 是正确的。

关于javascript - Javascript 中的站点地图 lastmod 日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46338846/

相关文章:

python - 将变量传递给 Django 2 中的 href 模板

PHP:将字符串设为大写但不将其中的 html 实体设为大写?

javascript - 在 Laravel 5.1 和 Vue JS 中保存多个数据动态表单

javascript - 使用 PHP 代理绕过 XMLHttpRequest 的同源策略有什么缺点?

php - 在 Laravel 4 中更改邮件传输

php - 使用 PHP 的 native SOAP 类时生成 WSDL?

javascript - 如何重新加载页面(AngularJs)

javascript - HTML选择表单onchange不会立即触发(即使没有焦点)

PHP soapCall 生成不需要的 htmlEntities

javascript - 按钮需要点击两次才能触发脚本