在 java.time 中从 `ZonedDateTime` 获取 `Instant`
Get `Instant` from `ZonedDateTime` in java.time
给定一个 ZonedDateTime
in the java.time package of Java 8 and later, how does one obtain an Instant
?
换个方向(Instant
→ ZonedDateTime
)就是:
ZonedDateTime zdt = ZonedDateTime.ofInstant( instant , zoneId ) ;
需要从 ZonedDateTime
→ Instant
转换为老派 java.util.Date
class.
java.util.Date date = Date.fromInstant( instant ) ;
您可以使用 toInstant()
default method from ChronoZonedDateTime
interface (which is inherited by ZonedDateTime
.
给定一个 ZonedDateTime
in the java.time package of Java 8 and later, how does one obtain an Instant
?
换个方向(Instant
→ ZonedDateTime
)就是:
ZonedDateTime zdt = ZonedDateTime.ofInstant( instant , zoneId ) ;
需要从 ZonedDateTime
→ Instant
转换为老派 java.util.Date
class.
java.util.Date date = Date.fromInstant( instant ) ;
您可以使用 toInstant()
default method from ChronoZonedDateTime
interface (which is inherited by ZonedDateTime
.