apoc.temporal.formatDuration函数在 Cypher 25 中已弃用
|
此函数已弃用。请改用 Cypher 的 |
语法 |
|
||
描述 |
将给定的持续时间(duration)格式化为指定的时间格式。 |
||
参数 |
名称 |
类型 |
描述 |
|
|
要格式化为字符串的持续时间值。 |
|
|
|
返回持续时间所采用的格式。 |
|
返回 |
|
||
用法示例
此函数处理模式字符串的方式与 DateTimeFormatter.ofPattern(<pattern>) 中使用的类似,但存在一些差异。下表为字母与 持续时间字段 (Duration Fields) 之间的转换对应关系:
| 字母 | 字段 |
|---|---|
|
year |
|
天 |
|
年中的月 |
|
年中的季度 |
|
周 |
|
小时 |
|
小时中的分钟 |
|
分钟中的秒 |
|
秒中的纳秒 |
|
milliseconds |
|
nanoseconds |
|
ISO 纳秒,即去除右侧多余零。例如: |
也可以使用 预定义的 Java 格式 或 Elastic 格式,但需要有时区或周年的格式除外,例如 basic_date_time 或 week_date_time。
apoc.temporal.formatDuration
RETURN apoc.temporal.formatDuration(duration({seconds: 6000}), "hour") AS output;
Cypher 的 format 函数
RETURN format(duration({seconds: 6000}), "hh") AS output;
| 输出 |
|---|
"01" |
apoc.temporal.formatDuration
RETURN apoc.temporal.formatDuration( duration({seconds: 10000}), "hour_minute") AS output;
Cypher 的 format 函数
RETURN format( duration({seconds: 10000}), "hh:mm") AS output;
| 输出 |
|---|
"02:46" |
apoc.temporal.formatDuration
WITH duration.between(datetime('2017-06-02T18:40:32.1234560'), datetime('2019-07-13T19:41:33')) AS duration
RETURN apoc.temporal.formatDuration(duration, "yy 'years' MM 'months' dd 'days' - HH:mm:ss SSSS") AS output
Cypher 的 format 函数
WITH duration.between(datetime('2017-06-02T18:40:32.1234560'), datetime('2019-07-13T19:41:33')) AS duration
RETURN format(duration, "yy 'years' MM 'months' dd 'days' - HH:mm:ss SSSS") AS output
| 输出 |
|---|
"02 年 01 个月 11 天 - 01:01:00 8765" |