/*
* 返回当前时间,格式:yyyy-MM-dd HH:mm:ss
*/
public static String getCurDateToYear() {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return simpleDateFormat.format(new Date());
}
/*
* 返回当前时间,格式:HH:mm:ss
*/
public static String getCurDateToHour() {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
return simpleDateFormat.format(new Date());
}
/*
* 返回当前时间,格式:yyyy-MM-dd
*/
public static String getCurDateToYearNoHours() {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
return simpleDateFormat.format(new Date());
}
/*
* 计算30分钟前时间
*/
public static String getCurDateToYearAdd30m() {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return simpleDateFormat.format(new Date().getTime()+60*30*1000);
}
/*
* 计算30天前时间
*/
public static String getCurDateToYearSub30day() {
Calendar now = Calendar.getInstance();
now.add(Calendar.DAY_OF_MONTH, -30);
String endDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(now.getTime());
return endDate;
}
/*
* 计算1天前时间
*/
public static String getCurDateToYearSub1day() {
Calendar now = Calendar.getInstance();
now.add(Calendar.DAY_OF_MONTH, -1);
String endDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(now.getTime());
return endDate;
}
返回不同格式的当前实时时间;
返回计算基于当前时间,1天、30天时间
可依次类推计算基于当前时间不同天数的时间值
亲测有效