alibaba / alibaba/fastjson2

[BUG]对象转JsonString后,时间发生变化

Open
#2,650 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
4.4k
Forks
613
Avg merge
1d 22h
Merged PRs (30d)
6

Description

### 问题描述
*简要描述您碰到的问题。*
fastjson版本从1.2.83升级到2.0.49之后,日期转为jsonString时,日期发生改变

### 环境信息
*请填写以下信息:*

- OS信息: [e.g.:Windows 11]
- JDK信息: [e.g.:Openjdk 1.8.0_312]
- 版本信息:[e.g.:Fastjson 2.0.49]

### 重现步骤
*如何操作可以重现该问题:*

String dateStr = "1900-01-01 00:06:43.0";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
Date date = simpleDateFormat.parse(dateStr);
System.out.println(date);
System.out.println(JSON.toJSONString(date, SerializerFeature.WriteDateUseDateFormat));
![image](https://github.com/alibaba/fastjson2/assets/26571477/b37d49d7-863e-448b-b3c5-ded746b88803)

### 相关日志输出
*请复制并粘贴任何相关的日志输出。*
打印结果如下:
![image](https://github.com/alibaba/fastjson2/assets/26571477/d2154671-fab6-4141-8ed4-5c4f1392b1d1)

Contributor guide

Open the contributing guide

Research direction

Start by running the supplied SimpleDateFormat and JSON.toJSONString example with Fastjson 1.2.83 and 2.0.49, comparing the serialized value for the 1900-01-01 date. Trace the date serialization path reached by JSON.toJSONString with SerializerFeature.WriteDateUseDateFormat. Done means the date is serialized without the reported change.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.