人类可读日期时间的模板?
Template for human readable date time?
{{ now }}
给出:2019-05-30 04:40:35.847147175 +0000 UTC m=+1983611.179295260
我想通过抓住前 2 个并加入 = 2019-05-30-04:40:35.847147175
.
来使它更易于阅读
如何做到这一点?
尝试失败:
time: {{ now || splitList " " | (not sure how to slice first 2) | join "-" }}
您应该查看整个列表 Sprig date functions, where Sprig 是包含在 Helm 中的 Go 模板函数库。
特别是您可能需要 date
函数,它使用 Go 格式字符串格式化 time.Time
值。正如链接文档所说:
...take this as the base date: Mon Jan 2 15:04:05 MST 2006
Write it in the format you want.
所以试试
{{ now | date "2006-01-02 15:04:05.000000" }}
Go (*time.Time).Format
函数的扩展示例可能也与此相关;例如,15:04:05.999999
应该删除尾随零,如果这是您想要的。
{{ now }}
给出:2019-05-30 04:40:35.847147175 +0000 UTC m=+1983611.179295260
我想通过抓住前 2 个并加入 = 2019-05-30-04:40:35.847147175
.
如何做到这一点?
尝试失败:
time: {{ now || splitList " " | (not sure how to slice first 2) | join "-" }}
您应该查看整个列表 Sprig date functions, where Sprig 是包含在 Helm 中的 Go 模板函数库。
特别是您可能需要 date
函数,它使用 Go 格式字符串格式化 time.Time
值。正如链接文档所说:
...take this as the base date:
Mon Jan 2 15:04:05 MST 2006
Write it in the format you want.
所以试试
{{ now | date "2006-01-02 15:04:05.000000" }}
Go (*time.Time).Format
函数的扩展示例可能也与此相关;例如,15:04:05.999999
应该删除尾随零,如果这是您想要的。