如当前时间为 2021-01-01 13:23:16 转换为2021-01-01 13:00:00
Long currentTime = System.currentTimeMillis();
//获取当前时间的整小时 +3600*1000*8 是因为 8个小时的时差 /(3600*1000) 计算出总共有多少小时 % 24求余得出当前小时
long currentHour = ((currentTime+3600*1000*8) / (3600*1000)) % 24;
Date date = new Date(currentTime);
//获取当前日的0:0:0点
SimpleDateFormat df = new SimpleDateFormat("yy-MM-dd");
String format = df.format(date);
long newCurrentTime = 0;
try {
newCurrentTime = df.parse(format).getTime() + currentHour * 3600000L;//加上计算出的当前日的小时
} catch (ParseException e) {
e.printStackTrace();
}
newCurrentTime 即为当前时间为整小时的时间戳