/**
* 获取完整时间
*
* @return
*/
def fullTime: String = {
val today = new Date
val f = new SimpleDateFormat("yyyyMMddHHmmss")
f.format(today)
}
/**
* 获取天时间
*
* @return
*/
def dayTime: String = {
val today = new Date
val f = new SimpleDateFormat("yyyyMMdd")
f.format(today)
}
def dirDayTime:String={
val today = new Date
val f = new SimpleDateFormat("yyyy/MM/dd")
f.format(today)
}
/**
* 增减日期
* @param date
* @param days
* @return
*/
def addDays(date:String,days:Int):String={
val sdf = new SimpleDateFormat("yyyyMMdd")
val d = sdf.parse(date)
val calendar = Calendar.getInstance()
calendar.setTime(d)
calendar.add(Calendar.DATE, days)
sdf.format(calendar.getTime)
}
/**
* 增减月份
* @param month
* @param months
* @return
*/
def addMonth(month:String,months:Int):String={
val sdf = new SimpleDateFormat("yyyyMM")
val m = sdf.parse(month)
val calendar = Calendar.getInstance()
calendar.setTime(m)
calendar.add(Calendar.MONTH, months)
sdf.format(calendar.getTime)
}
/**
* 获取月时间
* @return
*/
def monthTime:String={
val today = new Date
val f = new SimpleDateFormat("yyyyMM")
f.format(today)
}
/**
* 获取标准时间
*
* @return
*/
def standardTime:String ={
val currentTime: Date = new Date
val formatter: SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
formatter.format(currentTime)
}
/**
* 获取标准时间
*
* @return
*/
def standardTime:String ={
val currentTime: Date = new Date
val formatter: SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
formatter.format(currentTime)
}
/**
* 计算两个字符串的时间差,以分钟计
* success
*
* @param d1
* @param d2
* @return
*/
def calDateDiff(d1:String,d2:String):String={
val diff = calDate(d1,d2)
val hour = diff*1.0/(1000*60.0)
// println(s"时间差为:$hour 小时")
hour.formatted("%.2f")
}
/**
* 计算时间差
*
* @param d1
* @param d2
* @return
*/
def calDate(d1:String,d2:String):Long={
val date1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(d1)
val date2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(d2)
val time1 = date2.getTime
val time2 = date1.getTime
val diff = math.abs(time1-time2)
diff
}