当前位置:网站首页>时间戳和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
边栏推荐
- Datetime and logging module
- Knowing the details of redis RDB, you can step on many holes less
- Hystrix deployment
- JS foundation 1-js introduction and operator
- DataEase安装升级
- Fastposter v2.8.4 release e-commerce poster generator
- An idea plug-in that automatically generates unit tests, which improves the development efficiency by more than 70%!
- Yann LeCun新论文:构建自动智能体之路
- Training and recognition of handwritten digits through the lenet-5 network built by pytorch
- 【monkey】monkey测试入门
猜你喜欢
随机推荐
JS foundation 3
Hystrix deployment
壓縮解壓
利用soapUI获取freemarker的ftl文件模板
Metersphere实现UI自动化元素不可点击(部分遮挡)
Internet of things application case of wireless module transparent transmission technology
一种跳板机的实现思路
Katalon框架测试一个web页面操作实例代码
SQL中的DQL、DML、DDL和DCL是怎么区分和定义的
[practice] appium settings app is not running after 5000ms
Minimum stack < difficulty coefficient >
JSON module, hashlib, Base64
Secretary of the Ukrainian national security and National Defense Commission: will carry out precision strikes against targets in Russia
Katalon global variable is referenced in testobject
【SemiDrive源码分析】【X9芯片启动流程】32 - DisPlay模块分析 - RTOS侧
windows 10下载安装mysql5.7
Yann Lecun's new paper: the road to building automatic agents
How to use output in katalon
Several methods of using ABAP to operate Excel
使用API快捷创建ECS








