菜鸟笔记
提升您的技术认知

unable to obtain localdatetime from temporalaccessor: {} 错误解决-ag真人游戏

想要把  yyyy-mm-dd 格式的字符串,转为 localdatetime 对象,代码执行中抛出异常

exception in thread "main" java.time.format.datetimeparseexception: text '2021-10-31' could not be parsed: unable to obtain localdatetime from temporalaccessor: {},iso resolved to 2021-10-31 of type java.time.format.parsed
	at java.time.format.datetimeformatter.createerror(datetimeformatter.java:1920)
	at java.time.format.datetimeformatter.parse(datetimeformatter.java:1855)
	at java.time.localdatetime.parse(localdatetime.java:492)
	at com.agriculture.util.dateutil.main(dateutil.java:22)
caused by: java.time.datetimeexception: unable to obtain localdatetime from temporalaccessor: {},iso resolved to 2021-10-31 of type java.time.format.parsed
	at java.time.localdatetime.from(localdatetime.java:461)
	at java.time.format.parsed.query(parsed.java:226)
	at java.time.format.datetimeformatter.parse(datetimeformatter.java:1851)
	... 2 more
caused by: java.time.datetimeexception: unable to obtain localtime from temporalaccessor: {},iso resolved to 2021-10-31 of type java.time.format.parsed
	at java.time.localtime.from(localtime.java:409)
	at java.time.localdatetime.from(localdatetime.java:457)
	... 4 more
process finished with exit code 1
public static void main(string[] args) {
        datetimeformatter datetimeformatter = datetimeformatter.ofpattern("yyyy-mm-dd");
        localdatetime parse = localdatetime.parse("2021-10-31", datetimeformatter);
        system.out.println(parse);
    }

代码展示

public static void main(string[] args) {
        datetimeformatter datetimeformatter = datetimeformatter.ofpattern("yyyy-mm-dd");
        localdatetime parse = localdate.parse("2021-10-31", datetimeformatter).atstartofday();
        system.out.println(parse);
    }

执行结果

注:以上内容仅提供参考和交流,请勿用于商业用途,如有侵权联系本人删除!

网站地图