import java.text.SimpleDateFormat
import java.util.{Calendar, Date, Random}
object TimeDateUtil {
def getNowDate():String={
var now:Date = new Date()
var dateFormat:SimpleDateFormat = new SimpleDateFormat("yyyyMMdd")
var today = dateFormat.format( now )
today
}
def getNowDateWithMiddleHorizontaLine():String={
var now:Date = new Date()
var dateFormat:SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd")
var today = dateFormat.format( now )
today
}
def getTomorrow():String= {
var dateFormat: SimpleDateFormat = new SimpleDateFormat("yyyyMMdd")
var cal: Calendar = Calendar.getInstance()
cal.add(Calendar.DATE, +1)
var tomorrow = dateFormat.format(cal.getTime())
tomorrow
}
def getTomorrowWithMiddleHorizontaLine():String= {
var dateFormat: SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd")
var cal: Calendar = Calendar.getInstance()
cal.add(Calendar.DATE, +1)
var tomorrow = dateFormat.format(cal.getTime())
tomorrow
}
def getDayAfterTomorrow():String={
var dateFormat: SimpleDateFormat = new SimpleDateFormat("yyyyMMdd")
var cal: Calendar = Calendar.getInstance()
cal.add(Calendar.DATE, +2)
var dayAfterTomorrow = dateFormat.format(cal.getTime())
dayAfterTomorrow
}
def getCurrentHour(): String= {
val now:Date = new Date()
val dateFormat:SimpleDateFormat = new SimpleDateFormat("yyyyMMdd-HH:mm:ss")
val currentHour = dateFormat.format(now).substring(9,11)
currentHour.toString
}
def getCurrentTime():String={
val now:Date = new Date()
val dateFormat:SimpleDateFormat = new SimpleDateFormat("yyyyMMddHH:mm:ss")
dateFormat.format(now).substring(0,10)
}
def getDiffTime(startTime:String,endTime:String)={
val df:SimpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
// val df:SimpleDateFormat=new SimpleDateFormat("HH:mm:ss")
val begin:Date=df.parse(startTime)
val end:Date = df.parse(endTime)
val between:Long=(end.getTime-begin.getTime)/1000//转化成秒
// val hour:Float=between.toFloat/3600
between
// val decf:DecimalFormat=new DecimalFormat("#0.00")
// decf.format(hour)//格式化
}
def getRandomInt(Min: Int, Max: Int): Int = {
val rand = new Random
rand.nextInt(Max - Min + 1) + Min
}
}