ChronoZonedDateTime接口的toLocalDateTime()方法用於將此ChronoZonedDateTime轉換為LocalDateTime。
用法:
default LocalDateTime toLocalDateTime()
參數:此方法不接受任何參數。
返回值:此方法返回LocalDateTime,它與此ChronoZonedDateTime表示的LocalDateTime相同。
以下示例程序旨在說明toLocalDateTime()方法:
示例1:
// Java program to demonstrate
// ChronoZonedDateTime.toLocalDateTime() method
import java.time.*;
import java.time.chrono.*;
import java.time.chrono.*;
public class GFG {
public static void main(String[] args)
{
// create ChronoZonedDateTime object
ChronoZonedDateTime time
= ZonedDateTime
.parse(
"2018-12-06T19:21:12.123+05:30[Asia/Calcutta]");
// print ChronoZonedDateTime
System.out.println("ChronoZonedDateTime: "
+ time);
// print result
System.out.println("LocalDateTime: "
+ time.toLocalDateTime());
}
}
輸出:
ChronoZonedDateTime: 2018-12-06T19:21:12.123+05:30[Asia/Calcutta] LocalDateTime: 2018-12-06T19:21:12.123
示例2:
// Java program to demonstrate
// ChronoZonedDateTime.toLocalDateTime() method
import java.time.*;
import java.time.chrono.*;
import java.time.chrono.*;
public class GFG {
public static void main(String[] args)
{
// create ChronoZonedDateTime object
ChronoZonedDateTime time
= ZonedDateTime.parse(
"1918-10-25T23:12:38.543+02:00[Europe/Paris]");
// print ChronoZonedDateTime
System.out.println("ChronoZonedDateTime: "
+ time);
// print result
System.out.println("LocalDateTime: "
+ time.toLocalDateTime());
}
}
輸出:
ChronoZonedDateTime: 1918-10-25T23:12:38.543Z[Europe/Paris] LocalDateTime: 1918-10-25T23:12:38.543
參考: https://docs.oracle.com/javase/9/docs/api/java/time/chrono/ChronoZonedDateTime.html#toLocalDateTime–
相關用法
- Java ZonedDateTime toLocalDateTime()用法及代碼示例
- Java ChronoZonedDateTime from()用法及代碼示例
- Java ChronoZonedDateTime get()用法及代碼示例
- Java ChronoZonedDateTime until()用法及代碼示例
- Java ChronoZonedDateTime toLocalDate()用法及代碼示例
- Java ChronoZonedDateTime range()用法及代碼示例
- Java ChronoZonedDateTime getChronology()用法及代碼示例
- Java ChronoZonedDateTime toInstant()用法及代碼示例
- Java ChronoZonedDateTime isAfter()用法及代碼示例
- Java ChronoZonedDateTime toLocalTime()用法及代碼示例
- Java ChronoZonedDateTime getOffset()用法及代碼示例
- Java ChronoZonedDateTime getLong()用法及代碼示例
- Java ChronoZonedDateTime isEqual()用法及代碼示例
- Java ChronoZonedDateTime isBefore()用法及代碼示例
- Java ChronoZonedDateTime getZone()用法及代碼示例
注:本文由純淨天空篩選整理自ShubhamMaurya3大神的英文原創作品 ChronoZonedDateTime toLocalDateTime() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。