您的位置:首页 > 其它

String转换成时间戳(String Date 时间戳)

2016-03-17 16:07 155 查看
首先是 String转化成Date (java.util.Date )

String bookBeginusetime = "20160-03-17 15:55";


SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");


再是Date转换成毫秒数

Long beginUseTime = sdf.parse(bookBeginusetime).getTime();


getTime返回的是自1970年01月01日凌晨0点0分0秒至现在所经过的毫秒数,但数据库我们一般存的是时间戳,时间戳指的是1970年01月01日凌晨0点0分0秒到现在所经过的秒数。

所以最后要改成

Long beginUseTime = sdf.parse(bookBeginusetime).getTime()/1000;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: