当前位置:网站首页>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
边栏推荐
- 标签与路径
- Plato farm - a game of farm metauniverse with Plato as the goal
- BUUCTF WEB [BJDCTF2020]The mystery of ip
- Go language slicing operation
- Unable to create servlet under SRC subfile of idea
- Recovering data with MySQL binlog
- box-sizing
- 云原生KubeSphere部署Mysql
- Bert base Chinese Download (SMART)
- 如何实现点击一下物体播放一次动画
猜你喜欢
Use source insight to view and edit source code
软件测试周刊(第68期):解决棘手问题的最上乘方法是:静观其变,顺水推舟。
Record Alibaba cloud server mining program processing
mysql支持ip访问
Idea的src子文件下无法创建servlet
Embrace the new blue ocean of machine vision and hope to open a new "Ji" encounter for the development of digital economy
Realize several "Postures" in which a box is horizontally and vertically centered in the parent box
SSL certificate refund instructions
STM32 is connected to the motor drive, the DuPont line supplies power, and then the back burning problem
[daily question] chessboard question
随机推荐
Go language slicing operation
[csnote] ER diagram
Trier les principales utilisations de l'Agent IP réseau
产品开发都应该知道的8个网站,增强工作体验
Free and open source agricultural Internet of things cloud platform (version: 3.0.1)
教你快速开发一个 狼人杀微信小程序(附源码)
STM32 control stepper motor (ULN2003 + 28byj)
BUUCTF WEB [BJDCTF2020]The mystery of ip
Common problems of unity (1)
Free and open source intelligent charging pile SaaS cloud platform of Internet of things
[Blue Bridge Cup] April 17 provincial competition brushing training (the first three questions)
Resolve disagrees about version of symbol device_ create
Please help me see what this is, mysql5 5. Thanks
Recovering data with MySQL binlog
Learning materials
Redis deployment of cloud native kubesphere
洛谷P3236 [HNOI2014]画框 题解
XinChaCha Trust SSL Organization Validated
mysql8安装
leetcode:437. Path sum III [DFS selected or not selected?]