static YearMonth parse(CharSequence text)
描述 (Description)
java.time.YearMonth.parse(CharSequence text)方法从文本字符串(如2017-12 java.time.YearMonth.parse(CharSequence text)获取YearMonth的实例。
声明 (Declaration)
以下是java.time.YearMonth.parse(CharSequence text)方法的声明。
public static YearMonth parse(CharSequence text)
参数 (Parameters)
text - 要解析的文本,例如“2017-12”,而不是null。
返回值 (Return Value)
年 - 月,不是空的。
异常 (Exceptions)
DateTimeParseException - 如果无法解析文本。
例子 (Example)
以下示例显示了java.time.YearMonth.parse(CharSequence text)方法的用法。
package com.iowiki;
import java.time.YearMonth;
public class YearMonthDemo {
public static void main(String[] args) {
YearMonth date = YearMonth.parse("2017-12");
System.out.println(date);
}
}
让我们编译并运行上面的程序,这将产生以下结果 -
2017-12