add /GlobalCustomFormat

This commit is contained in:
Looly
2021-06-26 01:47:16 +08:00
parent 85e9bc11c2
commit 613b6f3ac5
16 changed files with 270 additions and 41 deletions

View File

@@ -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";