在将爬下来的网页解析需要的字段批量入口的时候(逻辑类似下面):

@Test
public void test_001(){ String TIME = "1990-04-15";
DateTime dateTime = DateTime.parse(TIME);
System.out.println(dateTime); }

程序抛出了一个时区异常:

org.joda.time.IllegalInstantException: Cannot parse "1990-04-15": Illegal instant due to time zone offset transition (Asia/Shanghai)

	at org.joda.time.format.DateTimeParserBucket.computeMillis(DateTimeParserBucket.java:471)
at org.joda.time.format.DateTimeParserBucket.computeMillis(DateTimeParserBucket.java:411)
at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:928)
at org.joda.time.DateTime.parse(DateTime.java:160)
at org.joda.time.DateTime.parse(DateTime.java:149)
at org.cc11001100.Test_001.test_001(Test_001.java:15)
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:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

这个是因为我们设置的时区不是东八区,所以解析的时候不应该使用DateTime而应该使用LocalDateTime:

@Test
public void test_001(){ String TIME = "1990-04-15";
// DateTime dateTime = DateTime.parse(TIME);
// System.out.println(dateTime); LocalDateTime localDateTime = LocalDateTime.parse(TIME);
System.out.println(localDateTime); }

使用LocalDateTime时会识别使用当前所在的时区。

JodaTime报时区异常错误的更多相关文章

  1. 3.Sprint 代理对象与原始对象的异常错误

    代码案例分析 Service层添加了注解@Transactional @Service @Transactional public class CustomerService extends Base ...

  2. [转载]IIS7报500.23错误的解决方法

    原文出处: 原文作者:pizibaidu 原文链接:http://pizibaidu.blog.51cto.com/1361909/1794446 背景:今天公司终端上有一个功能打开异常,报500错误 ...

  3. 总结Selenium自动化测试方法(六)常见的异常错误处理

    六.常见的异常错误处理 NoSuchElementException: Message: Unable to locate element: {"method":"xpa ...

  4. Java异常错误的面试题及答案

    1) Java中什么是Exception? 这个问题经常在第一次问有关异常的时候或者是面试菜鸟的时候问.我从来没见过面高级或者资深工程师的 时候有人问这玩意,但是对于菜鸟,是很愿意问这个的.简单来说, ...

  5. Tomcat正常启动,访问所有页面均报404异常,404异常总结

    今天遇到一个问题:Tomcat正常启动,访问所有页面均报404异常 404异常,很常见,大多情况是路径错误.web.xml文件映射路径写错.服务器设置.servlet的jar包未导进去或者没有随项目发 ...

  6. 【maven】【IDEA】idea中使用maven编译项目,报错java: 错误: 找不到符号 【2】

    =================================================================================== idea中使用maven编译项目 ...

  7. 【Azure App Service】C#下制作的网站,所有网页本地测试运行无误,发布至Azure之后,包含CHART(图表)的网页打开报错,错误消息为 Runtime Error: Server Error in '/' Application

    问题描述 C#下制作的网站,所有网页本地测试运行无误,发布至Azure之后,包含CHART(图表)的网页打开报错,错误消息为 Runtime Error: Server Error in '/' Ap ...

  8. Ceph RGW服务 使用s3 java sdk 分片文件上传API 报‘SignatureDoesNotMatch’ 异常的定位及规避方案

    import java.io.File;   import com.amazonaws.AmazonClientException; import com.amazonaws.auth.profile ...

  9. MVC3在IIS7.5发布(部署)报403.14错误的解决办法

    MVC3在IIS7.5发布(部署)报403.14错误的解决办法     错误现象: 报403.14 forbidden错误 web服务器被配置为不列出此目录的内容. 解决办法: 检查站点的处理程序映射 ...

随机推荐

  1. CodeForces Round #527 (Div3) D1. Great Vova Wall (Version 1)

    http://codeforces.com/contest/1092/problem/D1 Vova's family is building the Great Vova Wall (named b ...

  2. sublime text there are no packages available for installation 解决办法

    hosts  增加一行 : #50.116.33.29       sublime.wbond.net.

  3. p2 形状

    形状是物理引擎进行碰撞模拟计算的依据,是刚体最基本的属性. P2中使用Shape类来表示形状,通过刚体的addShape()方法,将形状添加到刚体中之后, 就可以随着刚体的移动.旋转不断更新,并进行碰 ...

  4. PHP之array_flip()方法

    array_flip — 交换数组中的键和值 array array_flip ( array $trans ) array_flip() 返回一个反转后的 array,例如 trans 中的键名变成 ...

  5. Js 中实现重定向的几种方式

    之所以要总结这个,是因为在项目中使用了 AJAX,当请求成功时需要重定向到另一个页面. 1 . <script type="text/javascript"> wind ...

  6. codepen & js demos

    codepen & js demos Mutation Observer & customize resize event listener & demo https://co ...

  7. 利用css3的text-shadow属性实现文字阴影乳白效果

    现在CSS3+html5的网页应用的越来越广泛了.很多网页中的字体同样可以用CSS3来实现炫酷的效果. 下面就介绍一下利用css3的text-shadow属性实现文字阴影乳白效果.这是在设计达人上面看 ...

  8. 【转】.gitignore失效的解决办法

    转自:http://foreverdo.diandian.com/post/2012-09-20/40038034798 How to make .gitignore works? Just got ...

  9. python打造12306余票实时监控

    # encoding=utf-8from Tkinter import *from ScrolledText import ScrolledTextimport urllib2import jsoni ...

  10. kerberos中的spn详解

    0x01 SPN定义    服务主体名称(SPN)是Kerberos客户端用于唯一标识给特定Kerberos目标计算机的服务实例名称.Kerberos身份验证使用SPN将服务实例与服务登录帐户相关联. ...