根据日期精度设置日期格式
我正在使用维基数据查询服务来获取某些地方的人口日期。输出给出格式为 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论