问题描述
我需要在固定的日期时间的代码中安排一个任务。为此,我使用一个ScheduledExecutorService方法 schedule(Runnable command,long delay,TimeUnit unit);
I need to schedule a task in my code at a fixed datetime. For that I'm using a ScheduledExecutorService with the method schedule(Runnable command, long delay, TimeUnit unit);
如何根据闰秒计算这个延迟?
How can I compute this delay according to leap seconds ?
目前我使用 Duration.between()
但是似乎并不知道闰秒:
For the moment I use Duration.between()
but it doesn't seem aware of leap seconds:
ZonedDateTime date1 = ZonedDateTime.of(2015, 06, 30, 23, 59, 59, 000000, ZoneOffset.UTC);
ZonedDateTime date2 = ZonedDateTime.of(2015, 07, 01, 00, 00, 00, 000000, ZoneOffset.UTC);
ZonedDateTime date3 = ZonedDateTime.of(2015, 07, 01, 00, 00, 01, 000000, ZoneOffset.UTC);
System.out.println(Duration.between(date1, date2)); // PT1S
System.out.println(Duration.between(date2, date3)); // PT1S
推荐答案
为了支持闰秒,您需要 ThreeTen-Extra 扩展jar文件。它为加上。
To support leap seconds you need the ThreeTen-Extra extension jar file. It has dedicated classes for UTC and TAI plus the table of leap seconds.
要计算持续时间,请使用专门的方法。
To calculate the duration, use the dedicated durationUntil() method.
这篇关于持续闰秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!