当前位置:网站首页>时间戳和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
边栏推荐
猜你喜欢

【实操】Appium Settings app is not running after 5000ms

Oracle 日期格式化异常:无效数字

Metersphere实现UI自动化元素不可点击(部分遮挡)

Realize an air conditioner with compose to bring you cool in summer

字符串 & 堆 & 方法区

JS基础3

Fastposter v2.8.4 release e-commerce poster generator

Summary of spatial temporal time series prediction modeling methods

无线模块透明传输技术的物联网应用案例

Katalon全局变量在TestObject引用
随机推荐
windows 10下载安装mysql5.7
Set up your own website (11)
利用soapUI获取freemarker的ftl文件模板
MytipartFile与File的相互转换
Oracle 日期格式化异常:无效数字
DlhSoft Kanban Library for WPF
Fastposter v2.8.4 release e-commerce poster generator
静态库的制作和使用
Transactions proof in appliedzkp zkevm (10)
JS foundation 6
sentinel
MySQL (III)
BLE蓝牙模块NRF518/NRF281/NRF528/NRF284芯片方案对比
JS基础3
知道 Redis RDB 这些细节,可以少踩很多坑
SQL中的DQL、DML、DDL和DCL是怎么区分和定义的
动态库(共享库)的制作和使用
Xshell和Xftp使用教程
metersphere使用js刷新当前页面
[Li Kou - dynamic planning] sort out topic 1: basic topics: 509, 70, 746, 62, 63, 343, 96 (with links, topic descriptions, problem solving methods and codes)