- 获取一小时开始时间问题
def getAgoTimeMillis(day: Int, hour:Int): Long = {
var cal: Calendar = Calendar.getInstance()
cal.add(Calendar.DATE, day)
cal.add(Calendar.HOUR, hour)
cal.add(Calendar.MINUTE,0)
cal.set(Calendar.SECOND, 0)
cal.set(Calendar.MILLISECOND, 0)
var agoTimeMillis = cal.getTime().getTime
agoTimeMillis
}
getAgoTimeMillis(0,1),这样调用获取下一个小时开始的时间,但是就是不行,最后改变方法:
def getAgoTimeMillis(day: Int, hour:Int): Long = {
var dateFormat: SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH")
var cal: Calendar = Calendar.getInstance()
cal.add(Calendar.DATE, day)
cal.add(Calendar.HOUR_OF_DAY, hour)
var agoTimeMillis = dateFormat.parse(dateFormat.format(cal.getTime())).getTime
agoTimeMillis
}
- Calendar.HOUR_OF_DAY代表24小时制,Calendar.HOUR代表12小时制,但是在scala中发现二者都是24小时制
网友评论