当前位置:网站首页>时间戳和date转换「建议收藏」
时间戳和date转换「建议收藏」
2022-06-28 10:53:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
/**
* @param s 时间戳
* @return date类型
*/
public static Date timeToDate(String s) {
long lt = new Long(s);
Date date = new Date(lt);
return date;
}
/** date 转时间戳
* @param date
* @return
*/
public static Long getatime(Date date){
return date.getTime();
}
/**
* @param s 时间戳
* @return date字符串
*/
public static String stampToDateString(String s) {
String res;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long lt = new Long(s);
Date date = new Date(lt);
res = simpleDateFormat.format(date);
return res;
}
public static void main(String[] args) {
//
String s = "1546071846000";
Date date=new Date();
String toString = date.toString();
System.out.println(toString);
long time = date.getTime();
System.out.println(stampToDateString(s));
System.out.println(timeToDate(s));
}发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/151098.html原文链接:https://javaforall.cn
边栏推荐
猜你喜欢

Summary of characteristics of five wireless transmission protocols of Internet of things

Information hidden in the trend chart of Hong Kong London gold market

建立自己的网站(11)

How to use K-line diagram for technical analysis

Katalon框架测试web(二十)自定义关键字以及上传弹窗操作

Yann Lecun's new paper: the road to building automatic agents

JS foundation 3

Markdown -- basic usage syntax

Move command

fastposter v2.8.4 发布 电商海报生成器
随机推荐
Metersphere uses JS to refresh the current page
Yann LeCun新论文:构建自动智能体之路
GDB简介
线程和线程池
【monkey】monkey测试入门
物联网无线通信应用中6种融合定位技术
File的io流与base64
MySQL(一)
将浏览器中的文件 url转换为File流
[Agora] get an Agora_ Example usage of refptr object
Six fusion positioning technologies in wireless communication application of Internet of things
JS foundation 3
Spatial-Temporal时间序列预测建模方法汇总
Ble Bluetooth module nrf518/nrf281/nrf528/nrf284 chip scheme comparison
字符串 & 堆 & 方法区
Katalon框架测试一个web页面操作实例代码
MytipartFile与File的相互转换
DlhSoft Kanban Library for WPF
fastposter v2.8.4 发布 电商海报生成器
[practice] 1364- implement a perfect waterfall flow component on the mobile terminal (with source code)