时间戳和时间的相互转换
来源:互联网 发布:有靠谱的网络兼职吗 编辑:程序博客网 时间:2024/06/04 20:13
时间戳和时间相互转换测试:
import java.io.File;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date;public class StampAndDate { public static void main(String[] args) { // TODO Auto-generated method stub if (args.length < 1) { return; } //输入文件名来连接文件 File file = new File(args[0]); System.out.println("最后修改时间(时间戳):" + file.lastModified()); System.out.println("最后修改时间(时间):"+stampToDate(String.valueOf(file.lastModified()))); try {System.out.println("最后修改时间(时间戳):" +dateToStamp(stampToDate(String.valueOf(file.lastModified()))));} catch (ParseException e) {// TODO Auto-generated catch blocke.printStackTrace();} } /* * 将时间转换为时间戳 */ public static String dateToStamp(String s) throws ParseException{ String res; SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS"); Date date = (Date) simpleDateFormat.parse(s); long ts = date.getTime(); res = String.valueOf(ts); return res; } /* * 将时间戳转换为时间 */ public static String stampToDate(String s){ String res; SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS"); long lt = new Long(s); Date date = new Date(lt); res = simpleDateFormat.format(date); return res; }}结果: 参数:1.txt 1.txt要先实现创建好
阅读全文
0 0
- 时间戳和时间的相互转换
- JavaScript 时间戳和时间相互转换
- 时间戳和时间相互转换
- 时间和时间戳的相互转换方法分享
- iOS时间和时间戳的相互转换
- ios 时间和时间戳的相互转换
- C# 时间戳和时间的相互转换
- Java时间和时间戳的相互转换
- Java时间和时间戳的相互转换
- python时间和时间戳之间的相互转换
- iOS开发中时间戳和时间的相互转换
- Java时间和时间戳的相互转换
- Java时间和时间戳的相互转换
- Java时间和时间戳的相互转换
- 时间戳与时间的相互转换
- 时间与时间戳的相互转换
- 时间与时间戳的相互转换
- golang获取当前时间、时间戳和时间字符串及它们之间的相互转换
- 延时,定时与临时文件
- Web前端开发学习笔记 (一)
- 字符串替换
- MySQL5.7半同步复制
- Selenium基础
- 时间戳和时间的相互转换
- activiti学习笔记(二) 获取流程实例
- Java基础复习——(一)Java基础概述
- JSP九大内置对象及四个作用域
- 1
- shell脚本编程习题浅析
- IO基础
- 【hautoj 1280】诡异的迷宫 【bfs 】
- http的状态码