一、java.util.Date
private void getDateTime1() {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date(System.currentTimeMillis());
String s = simpleDateFormat.format(date);
Log.d(TAG, "getDateTime1: " + s);
}
getDateTime1: 2020-10-18 13:08:27
二、java.util.Calendar
private void getDateTime2() {
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH) + 1;
int day = calendar.get(Calendar.DAY_OF_MONTH);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
Log.d(TAG, "getDateTime2: " + year + "年" + month + "月" + day + "日" + hour + ":" + minute + ":" + second);
}
getDateTime2: 2020年10月18日13:8:27