(1),获取当前日期时间,我来为大家科普一下关于java获取当前日期的前几天?下面希望有你要的答案,我们一起来看看吧!
java获取当前日期的前几天
(1),获取当前日期时间
String timeParse = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(timeParse);
String strDateTime = simpleDateFormat.format(new Date());
System.out.println("当前系统时间:" strDateTime);
(2),获取今日是周几
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
int weekIdx = calendar.get(Calendar.DAY_OF_WEEK) - 1;
switch (weekIdx) {
case 1:
System.out.println("今天是星期一");
break;
case 2:
System.out.println("今天是星期二");
break;
case 3:
System.out.println("今天是星期三");
break;
case 4:
System.out.println("今天是星期四");
break;
case 5:
System.out.println("今天是星期五");
case 6:
System.out.println("今天是星期六");
break;
default:
System.out.println("今天是星期日");
break;
}