scala获取某个时间间隔的时间

原始 dataFrame

//获取前7天的时间long类型
def getDaytimeTime(day:Int): Long = {
val cal = Calendar.getInstance
cal.add(Calendar.DATE, day)
val time: Date = cal.getTime
val fm = new SimpleDateFormat("yyyy-MM-dd")
val newTime = fm.parse(fm.format(time))
newTime.getTime
}

还可以是 DAY_OF_MONTHHOURMINUTEDay 等等,打印结果如下:

println(getDaytimeTime(-7))
1529251200000
原文地址:https://www.cnblogs.com/TTyb/p/9717433.html