原始 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_MONTH 、 HOUR 、 MINUTE 、 Day 等等,打印结果如下:
println(getDaytimeTime(-7))
1529251200000