1 <!--引入json转换工具--> <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson --> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.8.5</version> </dependency>
2
/** * 自定义日期转换格式 */ @Test public void testJsonDate() { Person person = new Person(1, "oliver", new Date()); // 指定日期转换格式 GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setDateFormat("yyyy-MM-dd"); Gson gson = gsonBuilder.create(); System.out.println(gson.toJson(person));
}