当前位置:网站首页>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;
}边栏推荐
- Docker install redis
- How to return ordered keys after counter counts the quantity
- I2C subsystem (IV): I2C debug
- The file marked by labelme is converted to yolov5 format
- Model transformation onnx2engine
- C#通用接口调用
- 迅雷chrome扩展插件造成服务器返回的数据js解析页面数据异常
- Can netstat still play like this?
- Process the dataset and use labelencoder to convert all IDs to start from 0
- VS 2019安装及配置opencv
猜你喜欢

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

Deep reinforcement learning for intelligent transportation systems: a survey paper reading notes

迅雷chrome扩展插件造成服务器返回的数据js解析页面数据异常

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

Check log4j problems using stain analysis

I2C 子系统(三):I2C Driver

Do you really understand relays?

力扣------网格中的最小路径代价

The idea cannot be loaded, and the market solution can be applied (pro test)

【PyG】理解MessagePassing过程,GCN demo详解
随机推荐
解决高并发下System.currentTimeMillis卡顿
Chart. JS multitooltip tag - chart js multiTooltip labels
Installation and use of memory leak tool VLD
Andwhere multiple or query ORM conditions in yii2
模型转换onnx2engine
I2C 子系统(一):I2C spec
Source code analysis | layout file loading process
[algebraic structure] group (definition of group | basic properties of group | proof method of group | commutative group)
PAT乙级常用函数用法总结
What happens between entering the URL and displaying the page?
Last update time of all sqlserver tables
VS 2019安装及配置opencv
分布式事务
Basic information of Promethus (I)
函数栈帧的创建与销毁
labelme标记的文件转换为yolov5格式
基于Qt的yolov5工程
Force deduction ----- the minimum path cost in the grid
MySQL practice 45 [SQL query and update execution process]
[principles of multithreading and high concurrency: 1_cpu multi-level cache model]