java获取当前时间前一个月的年月日时分秒

public static String getLastMonthTime(){
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MONTH, -1);
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH)+1;
int date = calendar.get(Calendar.DATE);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
return year+"-"+(month<10?"0"+month:month)+"-"+(date<10?"0"+date:date)+" "+(hour<10?"0"+hour:hour)+":"+(minute<10?"0"+minute:minute)+":"+(second<10?"0"+second:second);
}

java获取当前时间前一个月的年月日时分秒,布布扣,bubuko.com

java获取当前时间前一个月的年月日时分秒

上一篇:linux下C语言函数执行时间统计


下一篇:深入浅出 JavaScript 变量、作用域和内存 v 0.5