1: 计算连个字符串之间的额间隔天数
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date date2 = format.parse(item.getEdtime());
Date date = format.parse(item.getBgtime());
days=(int) ((date2.getTime() - date.getTime()) / 1000 / 60 / 60 / 24);
2:字符串转时间
SimpleDateFormat sdf = new SimpleDateFormat( " yyyy-MM-dd HH:mm:ss " )
2008-07-10 19:20:00 要把它转成日期,可以用 Date date = sdf.parse( " 2008-07-10 19:20:00 " );
输出date就是时间类型
3:时间转字符串
SimpleDateFormat sdf = new SimpleDateFormat( " yyyy-MM-dd HH:mm:ss " )
String str = sdf.format(new Date());
结果--》字符串内容的格式类似2008-07-10 19:20:00。
4:通过开始时间,和天数,,计算结束时间(再在线文档查看Calendar 用法)
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DATE, day);
calendar.getTime();
5:获取当天凌晨24点日期,
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 24);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.MILLISECOND, 0);
cal.getTime();