
- java.time 包類
- java.time - 首頁
- java.time - 時鐘
- java.time - 持續時間
- java.time - 立即
- java.time - LocalDate
- java.time - LocalDateTime
- java.time - LocalTime
- java.time - MonthDay
- java.time - OffsetDateTime
- java.time - OffsetTime
- java.time - 週期
- java.time - 年
- java.time - YearMonth
- java.time - ZonedDateTime
- java.time - ZoneId
- java.time - ZoneOffset
- java.time 包列舉
- java.time - 月份
- java.time 有用的資源
- java.time - 討論
java.time.ZonedDateTime.ofInstant() 方法示例
描述
java.time.ZonedDateTime.ofInstant(Instant instant, ZoneId zone) 方法從 Instant 和區域 ID 獲取 ZonedDateTime 的例項。
宣告
以下是 java.time.ZonedDateTime.ofInstant(Instant instant, ZoneId zone) 方法的宣告。
public static ZonedDateTime ofInstant(Instant instant, ZoneId zone)
引數
instant - 要從其建立日期時間且不為 null 的 instant。
zone - 時區,可以是偏移量,不為 null。
返回值
當地日期,不為 null。
異常
DateTimeException - 如果結果超出支援的範圍。
示例
以下示例展示了 java.time.ZonedDateTime.ofInstant(Instant instant, ZoneId zone) 方法的用法。
package com.tutorialspoint; import java.time.Instant; import java.time.ZonedDateTime; import java.time.ZoneId; public class ZonedDateTimeDemo { public static void main(String[] args) { ZonedDateTime date = ZonedDateTime.ofInstant(Instant.now(), ZoneId.systemDefault() ); System.out.println(date); } }
讓我們編譯並執行以上程式,這將產生以下結果 -
2017-03-28T13:58:14.543+05:30[Asia/Calcutta]
廣告