我该如何将日期格式化为时间戳记中的时代时间戳?

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

我正在使用Logback,并且我想打印一个时期时间戳而不是日期和时间。

[https://logback.qos.ch/manual/layouts.html#contextName引用了https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html,无法将日期格式化为时代。

我不敢相信此基本功能不可用,但我搜索了一段时间,却找不到它。

我发现对log4j log4j : current time in milliseconds是相同的问题,但是@thegeko提示那里%d{UNIX_MILLIS}在logback中对我不起作用。

有人知道吗?

logback
1个回答
0
投票

您可以使用此代码段打印Unix纪元:

<layout class="net.logstash.logback.layout.LogstashLayout">
    <timeZone>UTC</timeZone>
    <timestampPattern>[UNIX_TIMESTAMP_AS_NUMBER]</timestampPattern>
</layout>

参考:https://github.com/logstash/logstash-logback-encoder#customizing-timestamp

© www.soinside.com 2019 - 2024. All rights reserved.