Datetime and iso format

问题描述 投票:0回答:1

有时toString(datetime())返回不带前导零的毫秒数,以达到3的长度(yyyy-MM-dd'T'HH:mm:ss.SSSXXX)。是错误还是正常行为?

例如:

  • 2019-11-21T15:59:22。53 Z->应该是2019-11-21T15:59:22。053 Z
  • 2019-11-21T15:59:21。216 Z->确定
  • 2019-11-21T15:30:09。042 Z->确定

当我尝试将字符串转换为日期时,此行为会导致问题。

谢谢

neo4j cypher spring-data-neo4j
1个回答
1
投票

尝试使用apoc.temporal.format功能,指定iso_instant类型转换。

例如:

RETURN apoc.temporal.format(datetime("2019-11-21T22:04:19.13Z"), 'iso_instant');

将返回:

"2019-11-21T22:04:19.130Z"

[更新]

因为没有记录TOSTRING()函数来为datetime返回任何特定的ISO 8601字符串格式,所以不应该依赖于它返回特定的格式-甚至对于相同的datetime都返回相同的字符串]跨版本。

但是,如果您希望使用一种非APOC方法,该方法可用于neo4j的最新版本(例如3.5.12(已对其进行测试),下面是将当前TOSTRING()输出字符串修改为始终具有3位数的毫秒值:

// Generate a string.
// You can play with the number of digits after ".", and
// even eliminate the "." and any following digits.
WITH TOSTRING(datetime("2019-11-21T22:04:10.1Z")) AS d

// Always return a 3-digit millisecond time in result
WITH d, LENGTH(d) AS lth
RETURN d, CASE WHEN lth < 24
  THEN SUBSTRING(d, 0, lth-1) + SUBSTRING('.000Z', lth - 20)
  ELSE d END AS result
© www.soinside.com 2019 - 2024. All rights reserved.