mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add /GlobalCustomFormat
This commit is contained in:
@@ -450,6 +450,27 @@ public class JSONObjectTest {
|
||||
Assert.assertEquals(DateUtil.beginOfDay(date), parse.getDate("date"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCustomDateFormatTest(){
|
||||
JSONConfig jsonConfig = JSONConfig.create();
|
||||
jsonConfig.setDateFormat("#sss");
|
||||
jsonConfig.setOrder(true);
|
||||
|
||||
Date date = DateUtil.parse("2020-06-05 11:16:11");
|
||||
JSONObject json = new JSONObject(jsonConfig);
|
||||
json.set("date", date);
|
||||
json.set("bbb", "222");
|
||||
json.set("aaa", "123");
|
||||
|
||||
String jsonStr = "{\"date\":1591326971,\"bbb\":\"222\",\"aaa\":\"123\"}";
|
||||
|
||||
Assert.assertEquals(jsonStr, json.toString());
|
||||
|
||||
// 解析测试
|
||||
final JSONObject parse = JSONUtil.parseObj(jsonStr, jsonConfig);
|
||||
Assert.assertEquals(date, parse.getDate("date"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTimestampTest(){
|
||||
String timeStr = "1970-01-01 00:00:00";
|
||||
|
Reference in New Issue
Block a user