当前位置:网站首页>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
边栏推荐
- Buuctf Web [gxyctf2019] no dolls
- Sort out several uses of network IP agent
- Aviation core technology sharing | overview of safety characteristics of acm32 MCU
- Labels and paths
- Object.keys后key值数组乱序的问题
- Luogu p5540 [balkanoi2011] timeismoney | minimum product spanning tree problem solution
- HQL statement tuning
- C, calculation code of parameter points of two-dimensional Bezier curve
- Jiachen chapter Genesis "inner universe" joint Edition
- 云原生KubeSphere部署Mysql
猜你喜欢

梳理网络IP代理的几大用途

教你快速开发一个 狼人杀微信小程序(附源码)

Customize classloader and implement hot deployment - use loadclass

SSM框架系列——数据源配置day2-1

mysql中 innoDB执行过程分析

Mysql8 installation

SSM framework series - JUnit unit test optimization day2-3

22. Bracket generation

Process virtual address space partition

Van uploader upload picture implementation process, using native input to upload pictures
随机推荐
Image attribute of input: type attribute of fashion cloud learning -h5
免费试用一个月的服务器,并附上教程
Unlock openharmony technology day! The annual event is about to open!
mysql中 innoDB执行过程分析
Kubernetes 入门教程
C#,二维贝塞尔拟合曲线(Bézier Curve)参数点的计算代码
Buuctf Web [gxyctf2019] no dolls
[vulnhub range] - DC2
After the data of El table is updated, the data in the page is not updated this$ Forceupdate() has no effect
STM32 control stepper motor (ULN2003 + 28byj)
Golang implements MD5, sha256 and bcrypt encryption
Start mqbroker CMD failure resolution
Free and open source intelligent charging pile SaaS cloud platform of Internet of things
Process virtual address space partition
What are the forms of attack and tampering on the home page of the website
Go language: passing slices between functions
8 websites that should be known for product development to enhance work experience
Huawei cloud MVP email
Software testing weekly (issue 68): the best way to solve difficult problems is to wait and see the changes and push the boat with the current.
5 free audio material websites, recommended collection