当前位置:网站首页>将时间戳转为指定格式的时间
将时间戳转为指定格式的时间
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; }
边栏推荐
- Docker install redis
- Process the dataset and use labelencoder to convert all IDs to start from 0
- Parameter index out of range (1 > number of parameters, which is 0)
- 后管中编辑与预览获取表单的值写法
- Idea format code idea set shortcut key format code
- labelimg生成的xml文件转换为voc格式
- Three.js本地环境搭建
- VS 2019配置tensorRT
- Add automatic model generation function to hade
- Deep Reinforcement Learning for Intelligent Transportation Systems: A Survey 论文阅读笔记
猜你喜欢
Three. JS local environment setup
Three.js本地环境搭建
TCP 三次握手和四次挥手机制,TCP为什么要三次握手和四次挥手,TCP 连接建立失败处理机制
Spark on yarn资源优化思路笔记
Spark on yarn resource optimization ideas notes
MySql实战45讲【事务隔离】
[principles of multithreading and high concurrency: 1_cpu multi-level cache model]
Nasvit: neural architecture search of efficient visual converter with gradient conflict perception hypernetwork training
VS 2019安装及配置opencv
Privatization lightweight continuous integration deployment scheme -- 01 environment configuration (Part 2)
随机推荐
The core idea of performance optimization, dry goods sharing
Check log4j problems using stain analysis
从输入URL到页面展示这中间发生了什么?
MySQL practice 45 [global lock and table lock]
Thunderbolt Chrome extension caused the data returned by the server JS parsing page data exception
VS 2019 配置tensorRT生成engine
Add automatic model generation function to hade
js根据树结构查找某个节点的下面的所有父节点或者子节点
I2C 子系统(一):I2C spec
[Fuhan 6630 encodes and stores videos, and uses RTSP server and timestamp synchronization to realize VLC viewing videos]
Anhui University | small target tracking: large-scale data sets and baselines
左连接,内连接
模型转换onnx2engine
Idea format code idea set shortcut key format code
How to limit the size of the dictionary- How to limit the size of a dictionary?
Find the storage address of the elements in the two-dimensional array
VS 2019配置tensorRT
Counter统计数量后,如何返回有序的key
3D drawing example
一文带你了解 ZigBee