- java.time 包類
- java.time - Home
- java.time - Clock
- java.time - Duration
- java.time - Instant
- java.time - LocalDate
- java.time - LocalDateTime
- java.time - LocalTime
- java.time - MonthDay
- java.time - OffsetDateTime
- java.time - OffsetTime
- java.time - Period
- java.time - Year
- java.time - YearMonth
- java.time - ZonedDateTime
- java.time - ZoneId
- java.time - ZoneOffset
- java.time 包列舉
- java.time - Month
- java.time 有用資源
- java.time - 討論
java.time.LocalDateTime.withNano() 方法示例
描述
java.time.LocalDateTime.withNano(int nanoseconds) 方法返回一個將納秒更改的 LocalDateTime 副本。
宣告
以下是 java.time.LocalDateTime.withNano(int nanoseconds) 方法的宣告。
public LocalDateTime withNano(int nanoseconds)
引數
nanoseconds − 在結果中要設定的納秒,範圍從 0 到 999,999,999。
返回值
基於此日期並帶有所請求納秒的 LocalDateTime,非空。
異常
DateTimeException − 如果納秒值無效。
示例
以下示例展示了 java.time.LocalDateTime.withNano(int nanoseconds) 方法的用法。
package com.tutorialspoint;
import java.time.LocalDateTime;
public class LocalDateTimeDemo {
public static void main(String[] args) {
LocalDateTime date = LocalDateTime.parse("2017-01-03T10:15:30");
LocalDateTime result = date.withNano(50000);
System.out.println(result);
}
}
讓我們編譯並執行以上程式,這會生成以下結果 −
2017-01-03T10:15:30.000050
廣告