当前位置:网站首页>各类日期转化的utils
各类日期转化的utils
2022-04-23 06:15:00 【山顶看数据】
package com.asiniafo.dpi_new.dpi.utils;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;
/**
* 日期转换的utils
*/
public class DateUtil {
private static SimpleDateFormat sf = null;
//将字符串转换为时间戳
public static Long timeToLong(String time){
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
LocalDateTime parse = LocalDateTime.parse(time, formatter);
return LocalDateTime.from(parse).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
}
//将时间戳转成字符串
public static String getTimeStampToString(long time){
Date date = new Date(time);
sf = new SimpleDateFormat("yyyyMMddHHmmss");
return sf.format(date);
}
//获取当前时间
public static String getCurrentDate(){
Date date = new Date();
sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sf.format(date);
}
//将字符串转换为时间戳
public static long getStringToTimeStamp(String time) {
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
Date date = new Date();
try{
date = sf.parse(time);
}catch (Exception e){
e.printStackTrace();
}
return date.getTime();
}
//直接获取当前时间戳
public static String getTimeStamp(){
String currentDate = getCurrentDate();
sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
try {
date = sf.parse(currentDate);
}catch (Exception e){
e.printStackTrace();
}
return String.valueOf(date.getTime());
}
}
版权声明
本文为[山顶看数据]所创,转载请带上原文链接,感谢
https://blog.csdn.net/li1579026891/article/details/122449358
边栏推荐
- 直观理解 torch.nn.Unfold
- SHA512/384 原理及C语言实现(附源码)
- Visual studio 2019 installation and use
- 如何利用qemu搭建SOC protoype:80行代码实现一个Cortex M4 模拟器
- 初探智能指针之std::shared_ptr、std::unique_ptr
- PyTorch 10. 学习率
- Chapter 8 generative deep learning
- imx6ull-qemu 裸机教程1:GPIO,IOMUX,I2C
- 主流 RTOS 评估
- Solution to slow compilation speed of Xcode
猜你喜欢
随机推荐
Unable to determine the device handle for GPU 0000:02:00.0: GPU is lost.
torch.where能否传递梯度
美摄科技受邀LVSon2020大会 分享《AI合成虚拟人物的技术框架与挑战》
Gephi tutorial [1] installation
PyTorch 14. module类
By onnx checker. check_ Common errors detected by model
[8] Assertion failed: dims.nbDims == 4 || dims.nbDims == 5
关于短视频平台框架搭建与技术选型探讨
美摄助力百度“度咔剪辑”,让知识创作更容易
PyTorch 10. 学习率
关于短视频技术轮廓探讨
北峰通信助力湛江市消防支队构建PDT无线通信系统
scons 搭建嵌入式arm编译
基于51单片机的三路超声波测距系统(定时器方式测距)
Paddleocr image text extraction
直观理解 torch.nn.Unfold
使用proteus仿真STM32超声波SRF04测距!Code+Proteus
城市应急管理|城市突发事故应急通信指挥调度系统
Detailed explanation of unwind stack backtracking
[point cloud series] sg-gan: advantageous self attention GCN for point cloud topological parts generation







![Gephi tutorial [1] installation](/img/f7/a37be7ac1af3216b7491e500760ad6.png)

