当前位置:网站首页>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;
}边栏推荐
- MySql实战45讲【全局锁和表锁】
- Can netstat still play like this?
- Nasvit: neural architecture search of efficient visual converter with gradient conflict perception hypernetwork training
- How to return ordered keys after counter counts the quantity
- 为什么线程崩溃不会导致 JVM 崩溃
- Last update time of all sqlserver tables
- Privatization lightweight continuous integration deployment scheme -- 01 environment configuration (Part 2)
- 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)
- I2C 子系统(四):I2C debug
- Spark on yarn resource optimization ideas notes
猜你喜欢

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

函数栈帧的创建与销毁

From C to capable -- use the pointer as a function parameter to find out whether the string is a palindrome character

Check log4j problems using stain analysis

Thunderbolt Chrome extension caused the data returned by the server JS parsing page data exception

Add automatic model generation function to hade

The process of connecting MySQL with docker

I2C subsystem (II): I3C spec

TCP 三次握手和四次挥手机制,TCP为什么要三次握手和四次挥手,TCP 连接建立失败处理机制

Three.js本地环境搭建
随机推荐
后管中编辑与预览获取表单的值写法
Can netstat still play like this?
How to make backgroundworker return an object
The difference between componentscan and componentscans
[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
[combinatorics] Application of exponential generating function (multiple set arrangement problem | different balls in different boxes | derivation of exponential generating function of odd / even sequ
Idea set method call ignore case
How do you adjust the scope of activerecord Association in rails 3- How do you scope ActiveRecord associations in Rails 3?
Force deduction ----- the minimum path cost in the grid
用docker 连接mysql的过程
Tensorflow to pytorch notes; tf. gather_ Nd (x, y) to pytorch
I2C 子系统(二):I3C spec
MySql实战45讲【SQL查询和更新执行流程】
Three.js本地环境搭建
MySql實戰45講【SQL查詢和更新執行流程】
Docker install MySQL
MySQL practice 45 [global lock and table lock]
Are there any recommended term life insurance products? I want to buy a term life insurance.
Vs 2019 configuration du moteur de génération de tensorrt
【富瀚6630编码存录像,用rtsp服务器及时间戳同步实现vlc观看录像】