-
new Date().getTime()和System.currentTimeMillis()对比
public Date() {
this(System.currentTimeMillis());
}
从源码可以看出,new Date()其实就是调用了System.currentTimeMillis(),再传入自己的有参构造函数。不难看出,如果只是仅仅获取时间戳,即使是匿名的new Date()对象也会有些许的性能消耗, 从提升性能的角度来看,只是仅仅获取时间戳,直接调用System.currentTimeMillis()会更好一些。https://my.oschina.net/calmsnow/blog/2934475 -
当前整点的时间戳
笨办法,先搞成小时的format,然后再转时间戳
import java.text.SimpleDateFormat
import java.util.Date
val df: SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd-HH")
val curTime = System.currentTimeMillis()
val hourTime = df.format(curTime)
val hourTimestamp = df.parse(hourTime).getTime
网友评论