当前位置:网站首页>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
边栏推荐
- The continuous construction of the Internet industry platform is not only able to collect traffic
- 进程虚拟地址空间区域划分
- There is no need to crack the markdown editing tool typora
- Baserecyclerviewadapterhelper realizes pull-down refresh and pull-up loading
- Common problems of unity (1)
- Subscribe to Alibaba demo send business messages
- Free and open source agricultural Internet of things cloud platform (version: 3.0.1)
- PHP generates JSON to process Chinese
- Try the server for one month for free, and attach the tutorial
- 精度、速度完美平衡,最新图像分割SOTA模型重磅发布!!!
猜你喜欢
SSM framework series - JUnit unit test optimization day2-3
Kubernetes 入門教程
Image attribute of input: type attribute of fashion cloud learning -h5
31. Next arrangement
在线计算过往日期天数,计算活了多少天
SSM框架系列——数据源配置day2-1
Importerror after tensorflow installation: DLL load failed: the specified module cannot be found, and the domestic installation is slow
98. Error s.e.errormvcautoconfiguration $staticview reported by freemaker framework: cannot render error page for request
Servlet监听器&过滤器介绍
Embrace the new blue ocean of machine vision and hope to open a new "Ji" encounter for the development of digital economy
随机推荐
BUUCTF WEB [BJDCTF2020]The mystery of ip
php生成json处理中文
After the data of El table is updated, the data in the page is not updated this$ Forceupdate() has no effect
Please help me see what this is, mysql5 5. Thanks
Calculate the past date and days online, and calculate the number of live days
【csnote】ER图
HQL statement tuning
About the 'enum' enumeration type and structure.
BUUCTF WEB [GXYCTF2019]禁止套娃
If you were a golang interviewer, what questions would you ask?
Trier les principales utilisations de l'Agent IP réseau
8 websites that should be known for product development to enhance work experience
风尚云网学习-h5的input:type属性的image属性
Servlet监听器&过滤器介绍
Free and open source intelligent charging pile SaaS cloud platform of Internet of things
STM32 is connected to the motor drive, the DuPont line supplies power, and then the back burning problem
大家帮我看一下这是啥情况,MySQL5.5的。谢了
[csnote] ER diagram
【蓝桥杯】4月17日省赛刷题训练(前3道题)
世界读书日:我想推荐这几本书