mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
DateUtil.parse support iso8601
This commit is contained in:
parent
8319b00918
commit
9b2fc8aecf
@ -1943,6 +1943,8 @@ public class DateUtil extends CalendarUtil {
|
|||||||
builder.append(' ');
|
builder.append(' ');
|
||||||
String timePart = dateAndTime.get(1).replaceAll("[时分秒]", ":");
|
String timePart = dateAndTime.get(1).replaceAll("[时分秒]", ":");
|
||||||
timePart = StrUtil.removeSuffix(timePart, ":");
|
timePart = StrUtil.removeSuffix(timePart, ":");
|
||||||
|
//将ISO8601中的逗号替换为.
|
||||||
|
timePart = timePart.replace(',', '.');
|
||||||
builder.append(timePart);
|
builder.append(timePart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -780,4 +780,12 @@ public class DateUtilTest {
|
|||||||
dateTime = DateUtil.parse("2020-5-8 3:12:13");
|
dateTime = DateUtil.parse("2020-5-8 3:12:13");
|
||||||
Assert.assertEquals("2020-05-08 03:12:13", dateTime.toString());
|
Assert.assertEquals("2020-05-08 03:12:13", dateTime.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("ConstantConditions")
|
||||||
|
@Test
|
||||||
|
public void parseISO8601Test(){
|
||||||
|
String dt = "2020-06-03 12:32:12,333";
|
||||||
|
final DateTime parse = DateUtil.parse(dt);
|
||||||
|
Assert.assertEquals("2020-06-03 12:32:12", parse.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user