mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
DateUtil.parse支持毫秒时间戳
This commit is contained in:
parent
2a164a7692
commit
011f68e018
@ -16,6 +16,7 @@ import org.dromara.hutool.core.date.DateException;
|
|||||||
import org.dromara.hutool.core.date.DatePattern;
|
import org.dromara.hutool.core.date.DatePattern;
|
||||||
import org.dromara.hutool.core.date.DateTime;
|
import org.dromara.hutool.core.date.DateTime;
|
||||||
import org.dromara.hutool.core.date.format.DefaultDateBasic;
|
import org.dromara.hutool.core.date.format.DefaultDateBasic;
|
||||||
|
import org.dromara.hutool.core.math.NumberUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 纯数字的日期字符串解析,支持格式包括;
|
* 纯数字的日期字符串解析,支持格式包括;
|
||||||
@ -24,6 +25,7 @@ import org.dromara.hutool.core.date.format.DefaultDateBasic;
|
|||||||
* <li>yyyyMMddHHmmssSSS</li>
|
* <li>yyyyMMddHHmmssSSS</li>
|
||||||
* <li>yyyyMMdd</li>
|
* <li>yyyyMMdd</li>
|
||||||
* <li>HHmmss</li>
|
* <li>HHmmss</li>
|
||||||
|
* <li>毫秒时间戳</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @author looly
|
* @author looly
|
||||||
@ -49,6 +51,9 @@ public class PureDateParser extends DefaultDateBasic implements DateParser {
|
|||||||
return new DateTime(source, DatePattern.PURE_DATE_FORMAT);
|
return new DateTime(source, DatePattern.PURE_DATE_FORMAT);
|
||||||
} else if (length == DatePattern.PURE_TIME_PATTERN.length()) {
|
} else if (length == DatePattern.PURE_TIME_PATTERN.length()) {
|
||||||
return new DateTime(source, DatePattern.PURE_TIME_FORMAT);
|
return new DateTime(source, DatePattern.PURE_TIME_FORMAT);
|
||||||
|
} else if(length == 13){
|
||||||
|
// 时间戳
|
||||||
|
return new DateTime(NumberUtil.parseLong(source));
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new DateException("No pure format fit for date String [{}] !", source);
|
throw new DateException("No pure format fit for date String [{}] !", source);
|
||||||
|
@ -1130,4 +1130,11 @@ public class DateUtilTest {
|
|||||||
Assertions.assertNotNull(parse);
|
Assertions.assertNotNull(parse);
|
||||||
Assertions.assertEquals("2019-10-22 09:56:03", parse.toString());
|
Assertions.assertEquals("2019-10-22 09:56:03", parse.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void issueI8NMP7Test() {
|
||||||
|
final String str = "1702262524444";
|
||||||
|
final DateTime parse = DateUtil.parse(str);
|
||||||
|
Assertions.assertEquals("2023-12-11 10:42:04", Objects.requireNonNull(parse).toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user