1.查看当前日期时间并输出
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
System.out.println(sdf.format(cal.getTime()));
System.out.println("--------------------------------------");
2.输出明天的当前时间
Calendar cal2 = Calendar.getInstance();
cal2.add(Calendar.DATE, 1);//说明在日期上加1
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
System.out.println(sdf2.format(cal2.getTime()));
System.out.println("--------------------------------------");
3.查看这个月是几月,今天是几号,今天是星期几,这个星期是今年的第几个星期
Calendar cal3 = Calendar.getInstance();
int month = cal3.get(Calendar.MONTH);
int day = cal3.get(Calendar.DAY_OF_MONTH);
int week = cal3.get(Calendar.DAY_OF_WEEK);
int weekOfYear = cal3.get(Calendar.WEEK_OF_YEAR);
System.out.println("今天是"+(month+1)+"月");//第一个月是0
System.out.println("今天是今年的第"+weekOfYear+"个星期");//不变,但是一周的第一天是周日
System.out.println(cal3.get(Calendar.WEEK_OF_MONTH));//不变
System.out.println(cal3.get(Calendar.DAY_OF_YEAR));//不变
4.查看今天签到的用户(今天0点0分0秒至明天0点0分0秒)
Calendar cal4 = Calendar.getInstance();
cal4.set(Calendar.HOUR_OF_DAY, 0);
cal4.set(Calendar.MINUTE, 0);
cal4.set(Calendar.SECOND, 0);
Date begin = cal4.getTime();
cal4.add(Calendar.DATE, 1);
Date end = cal4.getTime();
Criteria cri = new Criteria();
cri.where("signTime").gte(begin).lte(end);
List<User> userList = mongo.find(new Query(cri), User.class);
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
System.out.println(sdf.format(cal.getTime()));
System.out.println("--------------------------------------");
2.输出明天的当前时间
Calendar cal2 = Calendar.getInstance();
cal2.add(Calendar.DATE, 1);//说明在日期上加1
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
System.out.println(sdf2.format(cal2.getTime()));
System.out.println("--------------------------------------");
3.查看这个月是几月,今天是几号,今天是星期几,这个星期是今年的第几个星期
Calendar cal3 = Calendar.getInstance();
int month = cal3.get(Calendar.MONTH);
int day = cal3.get(Calendar.DAY_OF_MONTH);
int week = cal3.get(Calendar.DAY_OF_WEEK);
int weekOfYear = cal3.get(Calendar.WEEK_OF_YEAR);
System.out.println("今天是"+(month+1)+"月");//第一个月是0
System.out.println("今天是"+day+"号");//不变
//周日是第一天。所以需减一。如果今天是周日,则需判断条件,因为1-1=0.
System.out.println("今天是星期"+(week-1));System.out.println("今天是今年的第"+weekOfYear+"个星期");//不变,但是一周的第一天是周日
System.out.println(cal3.get(Calendar.WEEK_OF_MONTH));//不变
System.out.println(cal3.get(Calendar.DAY_OF_YEAR));//不变
4.查看今天签到的用户(今天0点0分0秒至明天0点0分0秒)
Calendar cal4 = Calendar.getInstance();
cal4.set(Calendar.HOUR_OF_DAY, 0);
cal4.set(Calendar.MINUTE, 0);
cal4.set(Calendar.SECOND, 0);
Date begin = cal4.getTime();
cal4.add(Calendar.DATE, 1);
Date end = cal4.getTime();
Criteria cri = new Criteria();
cri.where("signTime").gte(begin).lte(end);
List<User> userList = mongo.find(new Query(cri), User.class);