【问题标题】:Date format in CalDav Propfind response - How to change it?CalDav Propfind 响应中的日期格式 - 如何更改它?
【发布时间】:2018-01-22 20:48:53
【问题描述】:

我正在尝试设置 CalDav Client vor iCloud。我正在使用以下 PROPFIND http curl:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<d:propfind xmlns:d="DAV:" xmlns:cs="http://calendarserver.org/ns/">

  <d:prop>
    <d:displayname/>
    <cs:getctag/>
    <d:resource-class/>
    <d:getlastmodified/>
  </d:prop>

</d:propfind>

响应是这样的:

    <getlastmodified>Mon, 22 Jan 2018 20:03:49 GMT</getlastmodified>
    <creationdate>2013-04-02T20:12:23Z</creationdate>
    <auto-provisioned xmlns="urn:mobileme:server-to-server"/>

我知道我想知道我是否可以得到不同格式的标签格式?最好是 2013-04-02T20:12:23Z。

非常感谢!

【问题讨论】:

  • 如果你的 shell 是 bash,你可以得到它: date -d 'Mon, 22 Jan 2018 20:03:49 GMT' --iso-8601=seconds
  • 谢谢!但我必须使用卷曲。你知道是否有一个 xml 选项吗?
  • 我不知道。

标签: xml date format icloud caldav


【解决方案1】:

我假设“标签”是指 getlastmodified 属性,它返回这个 日期:

Mon, 22 Jan 2018 20:03:49 GMT

你在问你是否可以让服务器在一个 不同的格式。 不,你不能,getlastmodified 的格式 WebDAV 属性被标准化为 rfc1123-date 在里面 WebDAV RFC (4918)。

重要提示:getlastmodified 不是标签!如果你需要一个标签来做 同步,使用 ETagBuilding a CalDAV client 文档很好地解释了这一点。

您可以在 shell 中解析并重新格式化您的 curl 输出。 你可以使用xmlstarlet 或其他工具:

lastmod=$(curl ... | xmlstarlet sel -N x="DAV:" -t -v "//x:getlastmodified")
date -jf \
  "%a, %d %b %Y %H:%M:%S GMT" \
  +"%Y-%M-%dT%H:%M:%SZ" \
  "${lastmod}"

...根据您的需要进行调整。

【讨论】:

  • 非常感谢!这就是我需要的信息。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-09-05
  • 2023-03-16
  • 1970-01-01
  • 1970-01-01
  • 2021-07-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多