根据日期精度设置日期格式

发布于 2025-01-15 21:02:18 字数 2030 浏览 4 评论 0原文

我正在使用维基数据查询服务来获取某些地方的人口日期。输出给出格式为 2010-01-01T00:00:00Z 的原始结果(作为示例)。我还检索了每个日期的日期精度。 查询 结果以 2010 年 1 月 1 日 格式显示日期,但下载 csv 或 tsv 文件后,日期仍以原始格式 显示2010-01-01T00:00:00Z

我想根据日期精度显示以下日期:

if (date precision = 11), display 2010 年 1 月 1 日
if (日期精度 = 10), 显示 2010 年 1 月
if (日期精度 = 9), 显示 2010
否则,只显示原始日期

我该如何执行此操作,以及如何强制下载的 csv 或 tsv 文件显示格式化日期?

SELECT DISTINCT
  ?place
  ?placeLabel
  ?population
  ?populationDate
  ?populationDatePrecision

WHERE {
  ?place p:P31 ?instanceOf.
  ?instanceOf ps:P31/wdt:279* wd:Q134390.
  
  OPTIONAL {
    ?place p:P1082 ?pop_statement .
    ?pop_statement ps:P1082 ?population;
      pqv:P585 [
                wikibase:timePrecision ?populationDatePrecision;
                wikibase:timeValue ?populationDate ].
  }
  
  minus { ?instanceOf pq:P582 ?endTime. }
  
  service wikibase:label { bd:serviceParam wikibase:language "en". }
} ORDER BY ?placeLabel

I am using Wikidata Query Service to get the dates of population of some places. The output gives a raw result in the format 2010-01-01T00:00:00Z (as an example). I have also retrieved the date precision of each date. The query results display the dates in 1 January 2010 format, but upon downloading the csv or tsv file, the dates are still displayed in the raw format 2010-01-01T00:00:00Z.

I would want to display the following dates based on their date precision:

if (date precision = 11), display 1 January 2010
if (date precision = 10), display January 2010
if (date precision = 9), display 2010
otherwise, just display the raw date

How can I do this, and how can I force the downloaded csv or tsv file to display the formatted dates?

SELECT DISTINCT
  ?place
  ?placeLabel
  ?population
  ?populationDate
  ?populationDatePrecision

WHERE {
  ?place p:P31 ?instanceOf.
  ?instanceOf ps:P31/wdt:279* wd:Q134390.
  
  OPTIONAL {
    ?place p:P1082 ?pop_statement .
    ?pop_statement ps:P1082 ?population;
      pqv:P585 [
                wikibase:timePrecision ?populationDatePrecision;
                wikibase:timeValue ?populationDate ].
  }
  
  minus { ?instanceOf pq:P582 ?endTime. }
  
  service wikibase:label { bd:serviceParam wikibase:language "en". }
} ORDER BY ?placeLabel

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文