mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
修复DateUtil针对ISO8601时间格式部分场景下的解析存在问题
This commit is contained in:
parent
6fd8f7f8d8
commit
6f8b4dd818
@ -2,7 +2,7 @@
|
|||||||
# 🚀Changelog
|
# 🚀Changelog
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.16.M1 (2023-03-12)
|
# 5.8.16.M1 (2023-03-14)
|
||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
* 【core 】 改进Calculator.conversion,兼容乘法符号省略写法(issue#2964@Github)
|
* 【core 】 改进Calculator.conversion,兼容乘法符号省略写法(issue#2964@Github)
|
||||||
@ -14,6 +14,7 @@
|
|||||||
* 【poi 】 修复SXSSFWorkbook调用setComment时错位的问题(issue#I6MBS5@Gitee)
|
* 【poi 】 修复SXSSFWorkbook调用setComment时错位的问题(issue#I6MBS5@Gitee)
|
||||||
* 【core 】 修复BeanUtil.hasGetter没有跳过getClass方法的问题(issue#I6MBS5@Gitee)
|
* 【core 】 修复BeanUtil.hasGetter没有跳过getClass方法的问题(issue#I6MBS5@Gitee)
|
||||||
* 【core 】 修复FileMagicNumber长度判断问题导致的越界异常(issue#I6MACI@Gitee)
|
* 【core 】 修复FileMagicNumber长度判断问题导致的越界异常(issue#I6MACI@Gitee)
|
||||||
|
* 【core 】 修复DateUtil针对ISO8601时间格式部分场景下的解析存在问题(issue#2981@Github)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.15 (2023-03-09)
|
# 5.8.15 (2023-03-09)
|
||||||
|
@ -237,22 +237,22 @@ public class DatePattern {
|
|||||||
public static final FastDateFormat JDK_DATETIME_FORMAT = FastDateFormat.getInstance(JDK_DATETIME_PATTERN, Locale.US);
|
public static final FastDateFormat JDK_DATETIME_FORMAT = FastDateFormat.getInstance(JDK_DATETIME_PATTERN, Locale.US);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UTC时间:yyyy-MM-dd'T'HH:mm:ss
|
* ISO8601时间:yyyy-MM-dd'T'HH:mm:ss
|
||||||
*/
|
*/
|
||||||
public static final String UTC_SIMPLE_PATTERN = "yyyy-MM-dd'T'HH:mm:ss";
|
public static final String UTC_SIMPLE_PATTERN = "yyyy-MM-dd'T'HH:mm:ss";
|
||||||
/**
|
/**
|
||||||
* UTC时间{@link FastDateFormat}:yyyy-MM-dd'T'HH:mm:ss
|
* ISO8601时间{@link FastDateFormat}:yyyy-MM-dd'T'HH:mm:ss
|
||||||
*/
|
*/
|
||||||
public static final FastDateFormat UTC_SIMPLE_FORMAT = FastDateFormat.getInstance(UTC_SIMPLE_PATTERN, TimeZone.getTimeZone("UTC"));
|
public static final FastDateFormat UTC_SIMPLE_FORMAT = FastDateFormat.getInstance(UTC_SIMPLE_PATTERN);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UTC时间:yyyy-MM-dd'T'HH:mm:ss.SSS
|
* ISO8601时间:yyyy-MM-dd'T'HH:mm:ss.SSS
|
||||||
*/
|
*/
|
||||||
public static final String UTC_SIMPLE_MS_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS";
|
public static final String UTC_SIMPLE_MS_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS";
|
||||||
/**
|
/**
|
||||||
* UTC时间{@link FastDateFormat}:yyyy-MM-dd'T'HH:mm:ss.SSS
|
* ISO8601时间{@link FastDateFormat}:yyyy-MM-dd'T'HH:mm:ss.SSS
|
||||||
*/
|
*/
|
||||||
public static final FastDateFormat UTC_SIMPLE_MS_FORMAT = FastDateFormat.getInstance(UTC_SIMPLE_MS_PATTERN, TimeZone.getTimeZone("UTC"));
|
public static final FastDateFormat UTC_SIMPLE_MS_FORMAT = FastDateFormat.getInstance(UTC_SIMPLE_MS_PATTERN);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UTC时间:yyyy-MM-dd'T'HH:mm:ss'Z'
|
* UTC时间:yyyy-MM-dd'T'HH:mm:ss'Z'
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
package cn.hutool.core.date;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class Issue2981Test {
|
||||||
|
/**
|
||||||
|
* https://github.com/dromara/hutool/issues/2981<br>
|
||||||
|
* 按照ISO8601规范,以Z结尾表示UTC时间,否则为当地时间
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("DataFlowIssue")
|
||||||
|
@Test
|
||||||
|
public void parseUTCTest() {
|
||||||
|
final String str1 = "2019-01-01T00:00:00.000Z";
|
||||||
|
final String str2 = "2019-01-01T00:00:00.000";
|
||||||
|
final String str3 = "2019-01-01 00:00:00.000";
|
||||||
|
|
||||||
|
Assert.assertEquals(1546300800000L, DateUtil.parse(str1).getTime());
|
||||||
|
Assert.assertEquals(1546272000000L, DateUtil.parse(str2).getTime());
|
||||||
|
Assert.assertEquals(1546272000000L, DateUtil.parse(str3).getTime());
|
||||||
|
}
|
||||||
|
}
|
@ -29,8 +29,9 @@ public class LocalDateTimeUtilTest {
|
|||||||
Assert.assertNotNull(of);
|
Assert.assertNotNull(of);
|
||||||
Assert.assertEquals(dateStr, of.toString());
|
Assert.assertEquals(dateStr, of.toString());
|
||||||
|
|
||||||
|
// 不加Z是标准当地时间,与UTC时间不同
|
||||||
of = LocalDateTimeUtil.ofUTC(dt.getTime());
|
of = LocalDateTimeUtil.ofUTC(dt.getTime());
|
||||||
Assert.assertEquals(dateStr, of.toString());
|
Assert.assertNotEquals(dateStr, of.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user