mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:20:07 +08:00
修复DateUtil.parseUTC时对-的处理问题
This commit is contained in:
parent
06fec1045c
commit
874e33458e
@ -20,6 +20,7 @@
|
||||
* 【core 】 修复computeIfAbsent问题(issue#I5PTN3@Gitee)
|
||||
* 【extra 】 修复Ftp中路径问题(issue#I5R2DE@Gitee)
|
||||
* 【core 】 修复ConcurrentHashMap.computeIfAbsent缺陷导致的问题
|
||||
* 【core 】 修复DateUtil.parseUTC时对-的处理问题(issue#2612@Github)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -867,6 +867,22 @@ public class DateUtil extends CalendarUtil {
|
||||
// 格式类似:2018-09-13T05:34:31+08:00
|
||||
return parse(utcString, DatePattern.UTC_WITH_XXX_OFFSET_FORMAT);
|
||||
}
|
||||
} else if(ReUtil.contains("-\\d{2}:?00", utcString)){
|
||||
// Issue#2612,类似 2022-09-14T23:59:00-08:00 或者 2022-09-14T23:59:00-0800
|
||||
|
||||
// 去除类似2019-06-01T19:45:43 -08:00加号前的空格
|
||||
utcString = utcString.replace(" -", "-");
|
||||
if(':' != utcString.charAt(utcString.length() - 3)){
|
||||
utcString = utcString.substring(0, utcString.length() - 2) + ":00";
|
||||
}
|
||||
|
||||
if (StrUtil.contains(utcString, CharUtil.DOT)) {
|
||||
// 带毫秒,格式类似:2018-09-13T05:34:31.999-08:00
|
||||
return new DateTime(utcString, DatePattern.UTC_MS_WITH_XXX_OFFSET_FORMAT);
|
||||
} else {
|
||||
// 格式类似:2018-09-13T05:34:31-08:00
|
||||
return new DateTime(utcString, DatePattern.UTC_WITH_XXX_OFFSET_FORMAT);
|
||||
}
|
||||
} else {
|
||||
if (length == DatePattern.UTC_SIMPLE_PATTERN.length() - 2) {
|
||||
// 格式类似:2018-09-13T05:34:31
|
||||
|
@ -0,0 +1,18 @@
|
||||
package cn.hutool.core.date;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Issue2612Test {
|
||||
|
||||
@Test
|
||||
public void parseTest(){
|
||||
Assert.assertEquals("2022-09-14 23:59:00",
|
||||
Objects.requireNonNull(DateUtil.parse("2022-09-14T23:59:00-08:00")).toString());
|
||||
|
||||
Assert.assertEquals("2022-09-14 23:59:00",
|
||||
Objects.requireNonNull(DateUtil.parse("2022-09-14T23:59:00-0800")).toString());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user