java.time.MonthDay.parse() 方法示例



說明

java.time.MonthDay.parse(CharSequence text) 方法從一個文字字串(例如 --10-15)獲取一個 MonthDay 例項。

宣告

以下是 java.time.MonthDay.parse(CharSequence text) 方法的宣告。

public static MonthDay parse(CharSequence text)

引數

text - 要解析的文字(例如 “--10-15”),非空。

返回值

本地區間的一天,非空。

異常

DateTimeParseException - 如果無法解析文字。

示例

以下示例展示了 java.time.MonthDay.parse(CharSequence text) 方法的用法。

package com.tutorialspoint;

import java.time.MonthDay;

public class MonthDayDemo {
   public static void main(String[] args) {
 
      MonthDay time = MonthDay.parse("--10-15");
      System.out.println(time);  
   }
}

讓我們編譯並執行上面的程式,它將產生以下結果 -

--10-15
廣告