计算单位为毫秒,比如
一小时的时间戳
60X60X1000=3,600,000
同理一天的时间戳
86400000
日期转时间戳JAVA代码如下:
public static long dateToStamp(String s) throws ParseException {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = simpleDateFormat.parse(s);
long ts = date.getTime();
return ts;
}
//long res = dateToStamp(“2021-10-17”);
//res =1634400000000
时间戳是从1970–01-01 00:00::00开始计算的。
本文介绍了如何将日期转换为时间戳,例如一小时的时间戳为3,600,000毫秒,一天的时间戳为86400000毫秒。给出的JAVA代码示例展示了从'yyyy-MM-dd'格式的日期字符串转化为时间戳的方法,并给出了2021-10-17日期转换后的结果1634400000000。时间戳是从1970-01-01 00:00:00开始计算的。
2161

被折叠的 条评论
为什么被折叠?



