当前位置:网站首页>Converts a timestamp to a time in the specified format
Converts a timestamp to a time in the specified format
2022-07-03 03:12:00 【Friendship years】
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class JsonTimeSerializer extends JsonSerializer<Long> {
private SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@Override
public void serialize(Long datel, JsonGenerator gen, SerializerProvider provider) throws IOException, JsonProcessingException {
if(datel.toString().length()<13){
datel= datel*1000L;
}
Date date= new Date(datel);
String value = dateFormat.format(date);
gen.writeString(value);
}
}
// Use
@JsonSerialize(using = JsonTimeSerializer.class) public void setAddTime(Long addTime) { this.addTime = addTime; }
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class JsonDateSerializer extends JsonSerializer<Long> {
private SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
@Override
public void serialize(Long datel, JsonGenerator gen, SerializerProvider provider) throws IOException, JsonProcessingException {
if(datel.toString().length()<13){
datel= datel*1000L;
}
Date date= new Date(datel);
String value = dateFormat.format(date);
gen.writeString(value);
}
}
// Use
@JsonSerialize(using = JsonDateSerializer.class)
public Long getAdd_time() {
return add_time;
}边栏推荐
- 从输入URL到页面展示这中间发生了什么?
- Do you really understand relays?
- Kubernetes cluster log and efk architecture log scheme
- com.fasterxml.jackson.databind.exc.InvalidFormatException问题
- ComponentScan和ComponentScans的区别
- Use of El tree search method
- L'index des paramètres d'erreur est sorti de la plage pour les requêtes floues (1 > Nombre de paramètres, qui est 0)
- Deep learning: multi-layer perceptron and XOR problem (pytoch Implementation)
- Deep reinforcement learning for intelligent transportation systems: a survey paper reading notes
- Segmentation fault occurs during VFORK execution
猜你喜欢

别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!

Docker install MySQL

Joking about Domain Driven Design (III) -- Dilemma

PAT乙级“1104 天长地久”DFS优化思路

Use of El tree search method

Nasvit: neural architecture search of efficient visual converter with gradient conflict perception hypernetwork training

Installation and use of memory leak tool VLD

The process of connecting MySQL with docker

左连接,内连接

MySql实战45讲【事务隔离】
随机推荐
Update and return document in mongodb - update and return document in mongodb
迅雷chrome扩展插件造成服务器返回的数据js解析页面数据异常
[combinatorics] number of solutions of indefinite equations (number of combinations of multiple sets R | number of non negative integer solutions of indefinite equations | number of integer solutions
Gavin teacher's perception of transformer live class - rasa project's actual banking financial BOT Intelligent Business Dialogue robot architecture, process and phenomenon decryption through rasa inte
用docker 連接mysql的過程
VS 2019 配置tensorRT生成engine
MySql实战45讲【全局锁和表锁】
VS code配置虚拟环境
Notifydatasetchanged not applicable to recyclerview - notifydatasetchanged not working on recyclerview
Use optimization | points that can be optimized in recyclerview
基于Qt的yolov5工程
Kubernetes family container housekeeper pod online Q & A?
On the adjacency matrix and adjacency table of graph storage
Sous - système I2C (IV): débogage I2C
PAT乙级常用函数用法总结
The idea cannot be loaded, and the market solution can be applied (pro test)
The difference between componentscan and componentscans
[Fuhan 6630 encodes and stores videos, and uses RTSP server and timestamp synchronization to realize VLC viewing videos]
敏捷认证(Professional Scrum Master)模拟练习题
Vs Code configure virtual environment