示例 1
- @Test
- public void test() throws IOException {
- Gson gson = new GsonBuilder()
- .setDateFormat("yyyy-MM-dd")
- .create();
- System.out.println(gson.toJson(new Date()));
- }
- 1
- 2
- 3
- 4
- 5
- 6
- 7
运行结果:
示例 2
- @Test
- public void test() throws IOException {
- Gson gson = new GsonBuilder()
- .setDateFormat("yyyy-MM-dd hh:mm:ss")
- .create();
- System.out.println(gson.toJson(new Date()));
- }
- 1
- 2
- 3
- 4
- 5
- 6
- 7
运行结果:
示例 3
- @Test
- public void test() throws IOException {
- Gson gson = new GsonBuilder()
- .setDateFormat("MM-dd-yyyy hh:mm")
- .create();
- System.out.println(gson.toJson(new Date()));
- }
运行结果:
本文暂时没有评论,来添加一个吧(●'◡'●)