kotlin import java.time.LocalDateTime import java.time.format.DateTimeFormatter fun main() { val currentDateTime = LocalDateTime.now() val futureDateTime = currentDateTime.plusDays(7) val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss") val formattedDateTime = currentDateTime.format(formatter) } kotlin import java.time.LocalDate import java.time.Period fun main() { val startDate = LocalDate.of(2021, 1, 1) val endDate = LocalDate.of(2021, 12, 31) val period = Period.between(startDate, endDate) } kotlin import java.time.Instant import java.time.ZoneId fun main() { val instant = Instant.now() val utcDateTime = instant.atZone(ZoneId.of("UTC")) val nyDateTime = instant.atZone(ZoneId.of("America/New_York")) }


上一篇:
下一篇:
切换中文