当前位置:网站首页>将时间戳转为指定格式的时间
将时间戳转为指定格式的时间
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;
}边栏推荐
- TCP 三次握手和四次挥手机制,TCP为什么要三次握手和四次挥手,TCP 连接建立失败处理机制
- Variable declarations following if statements
- Idea format code idea set shortcut key format code
- 函数栈帧的创建与销毁
- Docker install redis
- Installation and use of memory leak tool VLD
- Add some hard dishes to the interview: how to improve throughput and timeliness in delayed task scenarios!
- MySQL practice 45 [global lock and table lock]
- Left connection, inner connection
- Are there any recommended term life insurance products? I want to buy a term life insurance.
猜你喜欢

docker安装redis
![[shutter] monitor the transparency gradient of the scrolling action control component (remove the blank of the top status bar | frame layout component | transparency component | monitor the scrolling](/img/c3/b9a614001f80345a5c1cb3c68ab27c.jpg)
[shutter] monitor the transparency gradient of the scrolling action control component (remove the blank of the top status bar | frame layout component | transparency component | monitor the scrolling

Nasvit: neural architecture search of efficient visual converter with gradient conflict perception hypernetwork training
![MySQL practice 45 [global lock and table lock]](/img/23/fd58c185ae49ed6c04f1a696f10ff4.png)
MySQL practice 45 [global lock and table lock]

3D drawing example

Kubernetes family container housekeeper pod online Q & A?

Do you really understand relays?

左连接,内连接

用docker 連接mysql的過程

Super easy to use logzero
随机推荐
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)
[leectode 2022.2.15] lucky numbers in the matrix
MySQL Real combat 45 [SQL query and Update Execution Process]
Idea set method call ignore case
【富瀚6630编码存录像,用rtsp服务器及时间戳同步实现vlc观看录像】
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
模糊查询时报错Parameter index out of range (1 > number of parameters, which is 0)
I2C subsystem (IV): I2C debug
内存泄漏工具VLD安装及使用
Creation and destruction of function stack frame
你真的懂继电器吗?
Yiwen takes you to know ZigBee
Practice of traffic recording and playback in vivo
The process of connecting MySQL with docker
How to limit the size of the dictionary- How to limit the size of a dictionary?
Parameter index out of range (1 > number of parameters, which is 0)
模型转换onnx2engine
Kubernetes cluster log and efk architecture log scheme
Do you really understand relays?
What happens between entering the URL and displaying the page?