当前位置:网站首页>Create a gson object that formats the time zone. JSON parsing time formatting zoneddatetime
Create a gson object that formats the time zone. JSON parsing time formatting zoneddatetime
2022-06-28 06:13:00 【Not much pressure】
I was sent by different modules once ZonedDateTime Time format is different , According to the types of different modules new A custom gson Object to parse json.
private Gson getMyGson() {
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new JsonDeserializer<ZonedDateTime>() {
@Override
public ZonedDateTime deserialize(JsonElement json, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
if (json == null) {
return null;
}
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS").withZone(ZoneId.systemDefault());
return ZonedDateTime.from(fmt.parse(json.getAsString())).withZoneSameInstant(ZoneId.systemDefault());
}
}).registerTypeAdapter(ZonedDateTime.class, new JsonSerializer<ZonedDateTime>() {
@Override
public JsonElement serialize(ZonedDateTime zonedDateTime, Type type, JsonSerializationContext jsonSerializationContext) {
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
return new JsonPrimitive(fmt.format(zonedDateTime.truncatedTo(ChronoUnit.MILLIS)));
}
}).setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).setDateFormat("yyyy-MM-dd HH:mm:ss.SSS").create();
}
边栏推荐
- pytorch dataloader的长度 epoch与iteration的区别
- AutoCAD C# 多段線小銳角檢測
- Yygh-6-wechat login
- Openharmony gnawing paper growth plan -- json-rpc
- Alert pop-up processing in Web Automation
- YYGH-6-微信登录
- socke.io长连接实现推送、版本控制、实时活跃用户量统计
- MySQL common functions
- [MySQL] all query tables contain 20million data -- how to optimize SQL
- YYGH-7-用户管理
猜你喜欢

YYGH-7-用户管理

Yygh-8-appointment registration

What are the advantages of e-mail marketing? Why do sellers of shopline independent station attach so much importance to it?

AutoCAD C # Polyline Small Sharp angle Detection

AutoCAD C# 多段線小銳角檢測

Lombok @equalsandhashcode annotation how to make objects The equals () method compares only some attributes

Linux MySQL implements root user login without password

YYGH-6-微信登录

Oracle condition, circular statement

Linked list (I) - remove linked list elements
随机推荐
Is it safe to open a stock account? How to open a stock account?
mac下安装多个版本php并且进行管理
YYGH-BUG-02
Unity packaging webgl uses IIS to solve the error
PKG package node project (express)
Enum
ThreadLocal
【Paper Reading-3D Detection】Fully Convolutional One-Stage 3D Object Detection on LiDAR Range Images
使用pytorch和tensorflow计算分类模型的混淆矩阵
【Paper Reading-3D Detection】Fully Convolutional One-Stage 3D Object Detection on LiDAR Range Images
Drop down list processing in Web Automation
YYGH-8-预约挂号
At first glance, I can see several methods used by motionlayout
Oracle fundamentals summary
windows上安装redis并永久修改密码,及ssm框架集成redis
Yolact++ Pytorch环境
SQL and list de duplication
Introduction to openscap
Sharing tips for efficient scripting
socke.io長連接實現推送、版本控制、實時活躍用戶量統計