格式化日期时间,加上+02:00(%z)

时间:2018-02-14 11:04:20

标签: sesam

我有一个日期时间(UTC),我想更改为奥斯陆时区,格式包含+02:00。

输入是例如。 “〜t2016-06-09T11:14:21Z”。 输出应为:“2016-06-09T13:14:21 + 02:00”

我正在尝试使用以下日期时间格式,但没有运气:

["datetime-format", "Europe/Oslo", "%Y-%m-%dT%H:%M:%S%z", "_S.InstallationDate"]

根据文档,datetime-parse支持%z。 datetime格式不支持吗?我怎样才能解决我的问题?

1 个答案:

答案 0 :(得分:1)

目前不支持此功能。一种可能的解决方法是使用固定偏移量格式化时间戳(在示例中为2小时),以便您可以对字符串中的偏移量进行硬编码:

{
  "_id": "my-pipe",
  "type": "pipe",
  "source": {
    "type": "embedded",
    "entities": [{
      "_id": "foo",
      "InstallationDate": "~t2016-06-09T11:14:21Z"
    }]
  },
  "transform": {
    "type": "dtl",
    "rules": {
      "default": [
        ["comment", "shift by 2 hours (one hour in nanoseconds is 3.6e12)"],
        ["add", "formatted+0200",
          ["concat",
            ["datetime-format", "%Y-%m-%dT%H:%M:%S%z",
              ["datetime",
                ["+",
                  ["*", 2, 3600000000000],
                  ["integer", "_S.InstallationDate"]
                ]
              ]
            ], "+0200"]
        ]
      ]
    }
  }
}

这会给你:

[
  {
    "_id": "foo",
    "formatted+0200": "2016-06-09T13:14:21+0200"
  }
]