| | |
| | | return datatime;
|
| | | }
|
| | |
|
| | | |
| | | public static DateInfo dateDiff3(long startTime, long endTime) throws Exception {
|
| | | long nm = 1000 * 60;// 一分钟的毫秒数
|
| | | long nh = 1000 * 60 * 60;// 一小时的毫秒数
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | |
| | | /**
|
| | | * 判断是否同一个月
|
| | | * |
| | | * @param date1
|
| | | * @param date2
|
| | | * @return
|
| | |
| | | int month2 = calendar2.get(Calendar.MONTH);
|
| | | System.out.println(year1 + " " + month1);
|
| | | System.out.println(year2 + " " + month2);
|
| | | return calendar1.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR) && calendar1.get(Calendar.MONTH) == calendar2.get(Calendar.MONTH);
|
| | | return calendar1.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR)
|
| | | && calendar1.get(Calendar.MONTH) == calendar2.get(Calendar.MONTH);
|
| | | }
|
| | | |
| | | |
| | |
|
| | | /**
|
| | | * 指定日期加上天数后的日期
|
| | |
| | | ca.add(Calendar.DATE, num);
|
| | | return ca.getTime();
|
| | | }
|
| | |
|
| | |
|
| | | /**
|
| | | * 指定日期减去天数后的日期
|
| | |
| | | return Integer.parseInt(String.valueOf(between_days));
|
| | | }
|
| | |
|
| | | |
| | | /**
|
| | | * 字符串日期格式的计算
|
| | | *
|
| | |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
| | | return daysBetween(sdf.format(minDate), sdf.format(maxDate));
|
| | | }
|
| | |
|
| | |
|
| | | /**
|
| | | * 字符串日期格式的计算
|
| | |
| | |
|
| | | /**
|
| | | * 随机减去几分钟
|
| | | * |
| | | * @param date
|
| | | * @param min 随机添加的分钟数
|
| | | * @return
|
| | |
| | | return new Date(time);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 计算两时间月差
|
| | | * |
| | | * @param startDate <String>
|
| | | * @param endDate <String>
|
| | | * @return int
|
| | | * @throws ParseException
|
| | | */
|
| | | public static int getMonthSpace(String startDate, String endDate) throws ParseException {
|
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
|
| | | return getMonthSpace(sdf.parse(startDate), sdf.parse(endDate));
|
| | | }
|
| | |
|
| | | /**
|
| | | * @param args
|
| | | * @throws ParseException format() 对日期进行格式化处理 parse() 将日期设置为date类型
|
| | | * 计算两时间月差
|
| | | * |
| | | * @param startDate <String>
|
| | | * @param endDate <String>
|
| | | * @return int
|
| | | * @throws ParseException
|
| | | */
|
| | | public static void main(String[] args) throws ParseException {
|
| | | // TODO Auto-generated method stub
|
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
| | | Date d1 = sdf.parse("2016-09-08 00:00:00");
|
| | | Date d2 = sdf.parse("2016-09-08 00:00:00");
|
| | | public static int getMonthSpace(Date startDate, Date endDate) {
|
| | | Calendar start = Calendar.getInstance();
|
| | | Calendar end = Calendar.getInstance();
|
| | | start.setTime(startDate);
|
| | | end.setTime(endDate);
|
| | | int result = end.get(Calendar.MONTH) - start.get(Calendar.MONTH);
|
| | | int month = (end.get(Calendar.YEAR) - start.get(Calendar.YEAR)) * 12;
|
| | | return Math.abs(month + result);
|
| | | }
|
| | |
|
| | | System.out.println(daysBetween(d1, d2));
|
| | | System.out.println(daysBetween("2016-09-08 10:10:10", "2016-09-29 00:00:00"));
|
| | | public static void main(String[] args) throws ParseException {
|
| | | System.out.println(getMonthSpace("2012-02", "2013-01")); |
| | | }
|
| | |
|
| | | } |