Illegal instant due to time zone offset transition (Asia/Shanghai)_夏令时问题
Posted j-liu3323
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Illegal instant due to time zone offset transition (Asia/Shanghai)_夏令时问题相关的知识,希望对你有一定的参考价值。
项目报错信息:
Connot parse "1991-04-14",illegal instant due to time zone offset transition(Asia/Shanghai)
在网上查了一下说是由于夏令时问题引起了,那么什么是夏令时呢?
import org.joda.time.LocalDate;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
public static Date getBirthdayByIdCardNo(String IDCardNo) { Date birthday = null; if (StringUtils.isNotBlank(IDCardNo)) { int length = IDCardNo.length(); if (length == 15 || length == 18) { String strBirthday = null; if (length == 18) { //7—14位出生年月日 strBirthday = IDCardNo.substring(6, 14); } else { //7-12位出生年月日,比如670401代表1967年4月1日 strBirthday = StringUtils.leftPad(IDCardNo.substring(6, 12), 8, "19"); }
//DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyyMMdd");会报错 //birthday = LocalDate.parse(strBirthday, formatter).toDate();会报错
//SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");//所有的日期转换都要经过Calendar类,所以是线程不安全的。
//date = df.parse("2008-08-08");
birthday = DateUtils.parse(strBirthday, "yyyyMMdd");
}
} return birthday; }
import java.util.Date; import java.util.regex.Pattern; import org.joda.time.DateTime; public class DateUtils { public static final Pattern DATE_PATTERN = Pattern.compile("^\d{4}-\d{1,2}-\d{1,2}$"); public static Date parse(String time, String format) { return DateTimeUtils.toDate(DateTimeUtils.parse(time, format)); } } import java.util.Date; import org.apache.commons.lang3.StringUtils; import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormat; public class DateTimeUtils { public static Date toDate(DateTime dateTime){ return dateTime == null ? null : dateTime.toDate(); } public static DateTime parse(String time, String format) { if(StringUtils.isBlank(time)){ return null; } return DateTime.parse(time, DateTimeFormat.forPattern(format)); } }
以上是关于Illegal instant due to time zone offset transition (Asia/Shanghai)_夏令时问题的主要内容,如果未能解决你的问题,请参考以下文章
Dubbo-Fail to decode request due to: RpcInvocation
iOS 崩溃:__CRASHING_DUE_TO_PRIVACY_VIOLATION__
Account locked due to 25 failed logins
Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.