- java.time 包類
- java.time - 主頁
- java.time - 時鐘
- java.time - 時段
- java.time - 時刻
- java.time - 日期
- java.time - 日期時間
- java.time - 時間
- java.time - 月日
- java.time - 偏移日期時間
- java.time - 偏移時間
- java.time - 時段
- java.time - 年
- java.time - 年月
- java.time - 分割槽日期時間
- java.time - 分割槽識別符號
- java.time - 分割槽偏移量
- java.time 包列舉
- java.time - 月
- java.time 實用資源
- java.time - 討論
java.time.LocalDate.parse() 方法示例
說明
java.time.LocalDate.parse(CharSequence text, DateTimeFormatter formatter) 方法使用特定格式程式,從文字字串獲取 LocalDate 的一個例項。
宣告
以下是 java.time.LocalDate.parse(CharSequence text, DateTimeFormatter formatter) 方法的宣告。
public static LocalDate parse(CharSequence text, DateTimeFormatter formatter)
引數
text − 要解析的文字,例如“2017-02-03”,不能為空。
formatter − 要使用的格式程式,不能為空。
返回值
本地日期,不能為空。
異常
DateTimeParseException − 如果該文字無法解析。
示例
以下示例顯示了 java.time.LocalDate.parse(CharSequence text, DateTimeFormatter formatter) 方法的用法。
package com.tutorialspoint;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class LocalDateDemo {
public static void main(String[] args) {
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd MMM uuuu");
String date = "03 Feb 2017";
LocalDate localDate = LocalDate.parse(date, dateTimeFormatter);
System.out.println(localDate);
}
}
讓我們編譯並執行以上程式,它將生成以下結果 −
2017-02-03
廣告