EKsumic's Blog

let today = new Beginning();

Click the left button to use the catalog.

OR

使用SimpleMvcSitemap产生的Sitemap的lastmod里面的日期格式错误

使用SimpleMvcSitemap产生的Sitemap的lastmod里面的日期格式错误,Google无法读取这样的Sitemap

Google Console 提交Sitemap出错,日期无效:

报错:
发现无效日期。请修正日期或格式,然后重新提交。

详细信息:
父标记:url
标记:lastmod

根据《国际标准ISO 8601》 

  • 2020-4-20(×)
  • 2020-04-2(×)
  • 2020-4-2(×)
  • 2020-04-20(√)

日期格式标准应该是2020-04-20的表示方法。

Google可以另外接受这样的日期格式:

<lastmod>2020-07-01T13:24:31+09:00</lastmod>

 

解决方案:

public DateTime GetCorrectDate(DateTime dateTime)
{
    DateTime lta = dateTime;
    DateTime w3cDateTime = new DateTime(lta.Year, lta.Month, lta.Day, lta.Hour, lta.Minute, lta.Second, DateTimeKind.Local);
    return w3cDateTime;
}

使用方式:

List<SitemapNode> nodes = new List<SitemapNode>
{
    new SitemapNode(Url.Action("Index", "Home"))
    {
        ChangeFrequency = ChangeFrequency.Daily,
        LastModificationDate =GetCorrectDate(DateTime.UtcNow),               
        Priority =1.0M
    },          
};

参考文档:

https://github.com/uhaciogullari/SimpleMvcSitemap/issues/16

This article was last edited at 2020-07-01 22:30:01

RonaldjeF

WOW Cathie Wood holds these stocks for triple-digit upside — and they're on sale. Stable dividend stocks are great for the risk-averse. But for investors looking to add some pop to their portfolios, nothing beats the long-term upside of rapidly expanding growth stocks.

reply

2021-09-23 21:35:19

RonaldjeF

London Market Open: boohoo sinks after warning on profit margins Alliance News - Stock prices in London opened higher on Thursday with the internationally exposed FTSE 100 supported by sterling weakness, while on AIM fashion retailers were lower after boohoo cut its guidance.

reply

2021-10-12 03:10:39

* *