当前位置:网站首页>将时间戳转为指定格式的时间
将时间戳转为指定格式的时间
2022-07-03 03:08:00 【&友情岁月&】
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);
}
}
//使用
@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);
}
}
//使用
@JsonSerialize(using = JsonDateSerializer.class)
public Long getAdd_time() {
return add_time;
}边栏推荐
- Andwhere multiple or query ORM conditions in yii2
- docker安装redis
- TCP handshake three times and wave four times. Why does TCP need handshake three times and wave four times? TCP connection establishes a failure processing mechanism
- Use optimization | points that can be optimized in recyclerview
- Reset or clear NET MemoryStream - Reset or Clear . NET MemoryStream
- MySQL practice 45 lecture [transaction isolation]
- 3D drawing example
- 你真的懂继电器吗?
- 分布式事务
- The base value is too large (the error is marked as "08") [duplicate] - value too great for base (error token is'08') [duplicate]
猜你喜欢

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

超好用的日志库 logzero

MySql实战45讲【事务隔离】

函数栈帧的创建与销毁
![MySQL practice 45 lecture [transaction isolation]](/img/a5/5420651d6be51e892976f02be8c43c.png)
MySQL practice 45 lecture [transaction isolation]

Yiwen takes you to know ZigBee

Joking about Domain Driven Design (III) -- Dilemma

The process of connecting MySQL with docker

用docker 连接mysql的过程

Idea format code idea set shortcut key format code
随机推荐
Super easy to use logzero
Last update time of all sqlserver tables
Can netstat still play like this?
Edit and preview in the back pipe to get the value writing method of the form
js根据树结构查找某个节点的下面的所有父节点或者子节点
超好用的日志库 logzero
open file in 'w' mode: IOError: [Errno 2] No such file or directory
Unity3d human skin real time rendering real simulated human skin real time rendering "suggestions collection"
TCP 三次握手和四次挥手机制,TCP为什么要三次握手和四次挥手,TCP 连接建立失败处理机制
Find the storage address of the elements in the two-dimensional array
The idea cannot be loaded, and the market solution can be applied (pro test)
C # general interface call
About HTTP cache control
What happens between entering the URL and displaying the page?
How to use asp Net MVC identity 2 change password authentication- How To Change Password Validation in ASP. Net MVC Identity 2?
MySQL practice 45 lecture [transaction isolation]
二维数组中的元素求其存储地址
Creation and destruction of function stack frame
How to limit the size of the dictionary- How to limit the size of a dictionary?
Deep learning: multi-layer perceptron and XOR problem (pytoch Implementation)