博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java时间和时间戳的相互转换
阅读量:4454 次
发布时间:2019-06-07

本文共 730 字,大约阅读时间需要 2 分钟。

时间转换为时间戳:

/*      * 将时间转换为时间戳     */        public static String dateToStamp(String s) throws ParseException{        String res;        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");        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");        long lt = new Long(s);        Date date = new Date(lt);        res = simpleDateFormat.format(date);        return res;    }

 

转载于:https://www.cnblogs.com/weihuang6620/p/6772776.html

你可能感兴趣的文章
用myEclipse连接数据源生成动态数据报表
查看>>
[myeclipse]@override报错问题
查看>>
자주 쓰이는 정규표현식
查看>>
超简单的listview单选模式SingleMode(自定义listview item)
查看>>
vue-11-路由嵌套-参数传递-路由高亮
查看>>
HDU 1199 - Color the Ball 离散化
查看>>
[SCOI2005]骑士精神
查看>>
Hibernate原理解析-Hibernate中实体的状态
查看>>
六时车主 App 隐私政策
查看>>
C语言常见问题 如何用Visual Studio编写C语言程序测试
查看>>
Web用户的身份验证及WebApi权限验证流程的设计和实现
查看>>
hdu 2098 分拆素数和
查看>>
[ONTAK2010]Peaks kruskal重构树,主席树
查看>>
ECMAScript6-let与const命令详解
查看>>
iOS 使用系统相机、相册显示中文
查看>>
什么是敏捷设计
查看>>
SCSS的基本操作
查看>>
"安装程序无法定位现有系统分区" 问题解决
查看>>
.NET中栈和堆的比较
查看>>
【莫队】bzoj 3781,bzoj 2038,bzoj 3289
查看>>