当前位置:网站首页>Utils of various date conversion
Utils of various date conversion
2022-04-23 12:57:00 【Look at the data at the top of the mountain】
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;
/**
* Date converted utils
*/
public class DateUtil {
private static SimpleDateFormat sf = null;
// Convert string to timestamp
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();
}
// Convert... To time stamp
public static String getTimeStampToString(long time){
Date date = new Date(time);
sf = new SimpleDateFormat("yyyyMMddHHmmss");
return sf.format(date);
}
// Get the current time
public static String getCurrentDate(){
Date date = new Date();
sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sf.format(date);
}
// Convert string to timestamp
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();
}
// Get the current timestamp directly
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());
}
}
版权声明
本文为[Look at the data at the top of the mountain]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230615024669.html
边栏推荐
- 世界读书日:我想推荐这几本书
- Record a website for querying compatibility, string Replaceall() compatibility error
- STM32 control stepper motor (ULN2003 + 28byj)
- Packet capturing and sorting -- TCP protocol [8]
- 梳理网络IP代理的几大用途
- The accuracy and speed are perfectly balanced, and the latest image segmentation SOTA model is released!!!
- Luogu p3236 [hnoi2014] picture frame solution
- Unlock openharmony technology day! The annual event is about to open!
- Go language: passing slices between functions
- CVPR 2022&NTIRE 2022|首个用于高光谱图像重建的 Transformer
猜你喜欢
Learning materials
Resolve disagrees about version of symbol device_ create
Remote sensing image classification and recognition system based on convolutional neural network
软件测试周刊(第68期):解决棘手问题的最上乘方法是:静观其变,顺水推舟。
Object.keys后key值数组乱序的问题
Servlet监听器&过滤器介绍
标签与路径
Analysis of InnoDB execution process in MySQL
Fashion cloud learning - input attribute summary
Introduction to servlet listener & filter
随机推荐
C#,二维贝塞尔拟合曲线(Bézier Curve)参数点的计算代码
Buuctf Web [gxyctf2019] no dolls
Pytorch: a pit about the implementation of gradreverselayer
Recovering data with MySQL binlog
Softbank vision fund entered the Web3 security industry and led a new round of investment of US $60 million in certik
Calculate the past date and days online, and calculate the number of live days
SSM框架系列——Junit单元测试优化day2-3
【每日一题】棋盘问题
No idle servers? Import OVF image to quickly experience smartx super fusion community version
SSL certificate refund instructions
软件测试周刊(第68期):解决棘手问题的最上乘方法是:静观其变,顺水推舟。
4.DRF 权限&访问频率&过滤&排序
洛谷P5540 [BalkanOI2011] timeismoney | 最小乘积生成树 题解
If you were a golang interviewer, what questions would you ask?
Remote sensing image classification and recognition system based on convolutional neural network
【csnote】ER图
mysql中 innoDB执行过程分析
Introduction to kubernetes
PHP generates JSON to process Chinese
BUUCTF WEB [BJDCTF2020]The mystery of ip