字符串转换成localdateTime出错: Unable to obtain LocalDateTime from TemporalAccessor: {Year=2020, ...

今天写代码发现想将"2020-05-25"格式的字符串转成localDataTime格式,发现报错

  LocalDateTime time = LocalDateTime.parse("2020-05-25", DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        System.out.println(time);

控制台 报如下错误

java.time.format.DateTimeParseException: Text '2020-05-25' could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor: {},ISO resolved to 2020-05-25 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.slin.test.Test.testJ(Test.java:36)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.time.DateTimeException: Unable to obtain LocalDateTime from TemporalAccessor: {},ISO resolved to 2020-05-25 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)
	... 24 more
Caused by: java.time.DateTimeException: Unable to obtain LocalTime from TemporalAccessor: {},ISO resolved to 2020-05-25 of type java.time.format.Parsed
	at java.time.LocalTime.from(LocalTime.java:409)
	at java.time.LocalDateTime.from(LocalDateTime.java:457)
	... 26 more

上网搜了一下   此方法 可以解决

  https://segmentfault.com/q/1010000018526018

 

  • 6
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
javax.security.auth.login.loginexception: unable to obtain password from user 是 Java 身份验证系统中的一种异常情况。该异常通常出现在程序试图使用某个用户账户进行验证时,但是无法从用户获取到该账户的密码。这种情况通常表示用户输入的密码错误或者密码无法被系统获取到。 密码是用户账户的敏感信息,确保密码安全非常重要。如果程序无法获取到密码或者获取到了错误的密码,就无法对用户身份进行验证,这样就会出现安全漏洞。为了确保密码安全,Java 提供了一种加密方式,在程序中对密码进行加密,并将加密后的密码存储在数据库中。这样即使被黑客攻击,也无法获取到用户的真实密码,从而提高了系统的安全性。 当出现 javax.security.auth.login.loginexception: unable to obtain password from user 这种异常情况时,我们需要检查程序是否正确地实现了密码加密功能,同时检查用户是否输入了正确的密码。如果用户账户密码不被加密存储,那么就需要尽快处理该漏洞,将用户密码加密存储以提高系统安全性。此外,我们还可以尝试使用更安全的验证方式,例如双因素验证,以进一步提高系统的安全性。 总之,javax.security.auth.login.loginexception: unable to obtain password from user 异常提示我们密码加密与验证机制的重要性,我们需要在系统开发和使用过程中注意密码安全问题,确保系统的安全性和可靠性。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值