- java.time 包類
- java.time - 首頁
- java.time - 時鐘
- java.time - 持續時間
- java.time - Instant
- 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 - 時區 ID
- java.time - 時區偏移
- java.time 包列舉
- java.time - 月份
- java.time 實用資源
- java.time - 討論
java.time.OffsetDateTime.of() 方法示例
描述
java.time.OffsetDateTime.of(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond, ZoneOffset offset) 方法根據年、月、日、時、分、秒、納秒和偏移量獲取 OffsetDateTime 例項。
宣告
以下是 java.time.OffsetDateTime.of(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond, ZoneOffset offset) 方法的宣告。
public static OffsetDateTime of(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond, ZoneOffset offset)
public static OffsetDateTime of(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond, ZoneOffset offset)
引數
year - 要表示的年份,從 MIN_YEAR 到 MAX_YEAR
month - 要表示的月份,從 1(1 月)到 12(12 月)
dayOfMonth - 要表示的日期,從 1 到 31
hour - 要表示的小時數,從 0 到 23
minute - 要表示的分鐘數,從 0 到 59
second - 要表示的秒數,從 0 到 59
nanoOfSecond - 要表示的毫微秒數,從 0 到 999,999,999
offset - 區域偏移,非空
返回值
非空的日期和時間偏移。
異常
DateTimeException - 如果任何欄位的值超出範圍,或者日期對於年份月份無效。
示例
package com.tutorialspoint;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
public class OffsetDateTimeDemo {
public static void main(String[] args) {
OffsetDateTime date = OffsetDateTime.of(2017,2,3,6,30,40,50000,ZoneOffset.UTC);
System.out.println(date);
}
}
現場演示
2017-02-03T06:30:40.000050Z
列印頁面