当前位置:网站首页>各类日期转化的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
边栏推荐
猜你喜欢
美摄科技推出桌面端专业视频编辑解决方案——美映PC版
关于短视频技术轮廓探讨
FATFS FAT32学习小记
STM32多路测温无线传输报警系统设计(工业定时测温/机舱温度定时检测等)
机器视觉系列(02)---TensorFlow2.3 + win10 + GPU安装
Chapter 2 pytoch foundation 2
AUTOSAR从入门到精通100讲(五十二)-诊断和通信管理功能单元
Intuitive understanding of torch nn. Unfold
Detailed explanation of unwind stack backtracking
北峰通信助力湛江市消防支队构建PDT无线通信系统
随机推荐
torch.where能否传递梯度
重大安保事件应急通信系统解决方案
【点云系列】Relationship-based Point Cloud Completion
Chapter 2 pytoch foundation 1
PyTorch 22. PyTorch常用代码段合集
[8] Assertion failed: dims.nbDims == 4 || dims.nbDims == 5
[Point Cloud Series] SG - Gan: Adversarial Self - attachment GCN for Point Cloud Topological parts Generation
自组网灵活补盲|北峰油气田勘测解决方案
Detailed explanation of device tree
[8] Assertion failed: dims. nbDims == 4 || dims. nbDims == 5
Pytoch model saving and loading (example)
Infrared sensor control switch
LPDDR4笔记
【點雲系列】SG-GAN: Adversarial Self-Attention GCN for Point Cloud Topological Parts Generation
Device Tree 详解
机器学习——PCA与LDA
【点云系列】Unsupervised Multi-Task Feature Learning on Point Clouds
画 ArcFace 中的 margin 曲线
rearrange 和 einsum 真的优雅吗
防汛救灾应急通信系统