我怎样才能得到今天的具体时间 UTC java
How can I get a specific time Today in UTC java
我正在尝试获取 "today" 的特定 UTC 时间。
说世界标准时间下午 5 点
Instant.now().truncatedTo(ChronoUnit.DAYS).plus(1, ChronoUnit.DAYS)
要么
Instant.now().plus(1, ChronoUnit.DAYS).truncatedTo(ChronoUnit.DAYS)
我相信这让我到了今天的午夜。我只是延长这个
Instant.now().truncatedTo(ChronoUnit.DAYS).plus(1, ChronoUnit.DAYS).minus(7, ChronoUnit.HOURS);
或者有没有更好的方法。
大概就是这样的
ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
// this would be the today (might be in the past)
ZonedDateTime result = now.with(LocalTime.of(17, 0));
if (result.isBefore(now)) {
// This would be "next time it is 5 o-clock".
result = result.plusDays(1);
}
// if you really want an Instant out of it.
return result.toInstant();
我正在尝试获取 "today" 的特定 UTC 时间。
说世界标准时间下午 5 点
Instant.now().truncatedTo(ChronoUnit.DAYS).plus(1, ChronoUnit.DAYS)
要么
Instant.now().plus(1, ChronoUnit.DAYS).truncatedTo(ChronoUnit.DAYS)
我相信这让我到了今天的午夜。我只是延长这个
Instant.now().truncatedTo(ChronoUnit.DAYS).plus(1, ChronoUnit.DAYS).minus(7, ChronoUnit.HOURS);
或者有没有更好的方法。
大概就是这样的
ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
// this would be the today (might be in the past)
ZonedDateTime result = now.with(LocalTime.of(17, 0));
if (result.isBefore(now)) {
// This would be "next time it is 5 o-clock".
result = result.plusDays(1);
}
// if you really want an Instant out of it.
return result.toInstant();