1、Date对象转换为时间戳
Date date = new Date();
long times = ();
(times);
效果如下:
1508824283292
2、时间戳转换为Date日期对象
long times = ();
Date date = new Date(times);
(date);
效果如下:
Tue Oct 24 13:49:28 CST 2017
3、时间戳转换为指定日期格式
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long times = ();
String str = (times);
(str);
效果如下:
2017-10-24 13:50:46
4、时间字符串<年月日时分秒毫秒 >转为 时间戳
20180914150324
转为
1536908604990
代码:
//大写HH:24小时制,小写hh:12小时制
//毫秒:SSS
//指定转化前的格式
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
//转化后为Date日期格式
Date date = (());
//Date转为时间戳long
long shootTime = ();
(shootTime);