java.time.YearMonth.parse(CharSequence text)
方法从文本字符串(如2017-12
)获取YearMonth
的实例。
声明
以下是java.time.YearMonth.parse(CharSequence text)
方法的声明。
public static YearMonth parse(CharSequence text)
参数
text
- 要解析的文本,例如"2017-12"
,而不是null
。
返回值
年月值,不是null
。
例外
DateTimeParseException
- 如果无法解析文本。
示例
以下示例显示了java.time.YearMonth.parse(CharSequence text)
方法的用法。
package com.zaixian;
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
上一篇:
java.time.YearMonth类
下一篇:
java.time.ZonedDateTime类