经常处理一些日期相关的信息,Calendar类是处理日期的常用类,写下几个方法,不用重复造轮子了. 1.求上一天,下一天的日期 Date now = new Date();Calendar c = Calendar.getInstance();c.setTime(now);c.add(Calendar.DAY_OF_MONTH, -1); // 下一天,上一天-1改为1Date yesterday = c.getTime();SimpleDateFormat sdf = new SimpleDa
public static List getWeekendInMonth(int year, int month) { List list = new ArrayList(); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year);// 不设置的话默认为当年 calendar.set(Calendar.MONTH, month - 1);// 设置月份 calendar.set(Calendar
类 Date 在 JDK 1.1 之前,类 Date 有两个其他的函数.它允许把日期解释为年.月.日.小时.分钟和秒值. 它也允许格式化和解析日期字符串.不过,这些函数的 API 不易于实现国际化.从 JDK 1.1 开始,应 该使用 Calendar 类实现日期和时间字段之间转换,使用 DateFormat 类来格式化和解析日期字符串. Date 中的相应方法已废弃. Date() 分配 Date 对象并初始化此对象,以表示分配它的时间(精确到毫秒). Date(long date) 分配 D