静态方法
public static String getDate() { Calendar ca = Calendar.getInstance(); int year = ca.get(Calendar.YEAR);//获取年份 int month = ca.get(Calendar.MONTH) + 1;//获取月份 int day = ca.get(Calendar.DATE);//获取日 int hour = ca.get(Calendar.HOUR_OF_DAY);//小时 int minute = ca.get(Calendar.MINUTE);//分; int second = ca.get(Calendar.SECOND);//秒 String time; if (minute < 10 && second < 10) { time = year + "-" + month + "-" + day + " " + hour + ":" + "0" + minute + ":" + "0" + second; } else if (minute < 10 && second >= 10) { time = year + "-" + month + "-" + day + " " + hour + ":" + "0" + minute + ":" + second; } else if (minute >= 10 && second < 10) { time = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + "0" + second; } else { time = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second; } return time; }