java获取当前时间戳毫秒(附java时间的相互转换的方法)

Java获取时间戳及与时间的相互转换的方法,时间戳(timestamp):一个能表示一份数据在某个特定时间之前已经存在的、 完整的、 可验证的数据,通常是一个字符序列,唯一地标识某一刻的时间。指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。

Java中获取时间戳的方式有:

1、通过System

System.currentTimeMillis()

2、通过Date来获取

public static Long dateToTimestamp(Date date) {
long time = date.getTime();
return time;
}

Java中获取的均为毫秒数,可根据需要自行进行转换为秒

Java获取时间戳及与时间的相互转换的方法

java时间戳转为指定格式的时间字符串

public static String timestampToDateStr(Long timestamp) {
Date date = new Date(timestamp);
DateFormat dateFormat = new SimpleDateFormat("yyyy:MM:dd hh:mm:ss");
String format = dateFormat.format(date);
return format;
版权声明:
作者:Joker 链接:https://456787.xyz/archives/1079
文章版权归作者所有,转载请注明出处。
THE END
分享
二维码
打赏
< <上一篇
下一篇>>