| 限定符和类型 | 方法和说明 |
|---|---|
static Date |
addDate(Date date,
int day)
给指定日期加(减)天数
比如时间2014-05-12 12:00:00 DateCalcUtils.addDate(date,1); 2014-05-11 12:00:00
比如时间2014-05-12 12:00:00 DateCalcUtils.addDate(date,-1); 2014-05-13 12:00:00
|
static Date |
addHour(Date date,
int hours)
给指定日期加(减)小时数
比如时间2014-05-12 12:00:00 DateCalcUtils.addHour(date,1); 2014-05-12 13:00:00
比如时间2014-05-12 12:00:00 DateCalcUtils.addHour(date,-1); 2014-05-12 11:00:00
|
static Date |
addMilliSecond(Date date,
int milliSecond)
给指定时间加/减毫秒数
|
static Date |
addMinute(Date date,
int minutes)
给指定日期加(减)分钟数
比如时间2014-05-12 12:00:00 DateCalcUtils.addMinute(date,2); 2014-05-12 12:02:00
比如时间2014-05-12 12:00:00 DateCalcUtils.addMinute(date,-2); 2014-05-12 11:58:00
|
static Date |
addMonth(Date date,
int months)
给指定日期加(减)月数
比如时间2014-05-12 12:10:00 DateCalcUtils.addMonth(date,1); 2014-06-12 12:10:00
比如时间2014-05-12 12:10:00 DateCalcUtils.addMonth(date,-1); 2014-04-12 12:10:00
|
static Date |
addMonth(Date date,
int months,
boolean escapeDays)
给指定日期加(减)月数
比如时间2014-05-12 12:10:00 DateCalcUtils.addMonth(date,1,false); 2014-06-12 12:10:00
比如时间2014-05-12 12:10:00 DateCalcUtils.addMonth(date,1,true); 2014-06-01 00:00:00
|
static Date |
addSecond(Date date,
int seconds)
给指定日期加(减)秒数
比如时间2014-05-12 12:00:00 DateCalcUtils.addSecond(date,2); 2014-05-12 12:00:02
比如时间2014-05-12 12:00:00 DateCalcUtils.addSecond(date,-2); 2014-05-12 11:59:58
|
static Date |
addYear(Date date,
int years)
给指定日期加(减)年份数
比如时间2014-05-12 12:10:00 DateCalcUtils.addYear(date,1); 2015-06-12 12:10:00
比如时间2014-05-12 12:10:00 DateCalcUtils.addYear(date,-1); 2013-04-12 12:10:00
|
static int |
dateDiff(int datePart,
Date startDate,
Date endDate) |
static int |
get12Hour(Date date)
从日期中获取小时(12制)
比如时间2014-05-12 22:10:00 DateCalcUtils.get12Hour(date); 10
|
static int |
get24Hour(Date date)
从日期中获取小时(24制)
比如时间2014-05-12 22:10:00 DateCalcUtils.get24Hour(date); 22
|
static Date |
getBeginDayInMonth(Date date)
从日期中获取月份第一天
比如时间2014-05-12 DateCalcUtils.getBeginDayInMonth("2014-05-12","yyyy-MM-dd"); 204-05-01
|
static int |
getDay(Date date)
从日期中获取天
比如时间2014-05-12 12:10:00 DateCalcUtils.getDay(date); 12
|
static int |
getDaysBetween(Date start,
Date end)
计算两个日期之间相差的天数,测试发现还是有问题(没问题)
比如Date start = 2012-2-12
Date end = 2012-3-1
DateCalcUtils.getDaysBetween(start,end) 18
|
static Date |
getEndDayInMonth(Date date)
从日期中获取月份最后一天
比如时间2014-05-12 DateCalcUtils.getEndDayInMonth(date); 204-05-31
|
static int |
getMillisecond(Date date)
从日期中获取毫秒
比如时间2014-05-12 22:10:00 DateCalcUtils.getMillisecond(date); 151
|
static int |
getMinute(Date date)
从日期中获取分钟
比如时间2014-05-12 22:10:00 DateCalcUtils.getMinute(date); 10
|
static int |
getMonth(Date date)
从日期中获取月份
比如时间2014-05-12 12:10:00 DateCalcUtils.getMonth(date); 5
|
static int |
getMonthsBetween(Date start,
Date end)
计算两个日期之间相差的月份
比如Date start = 2012-2-12
Date end = 2012-3-1
DateCalcUtils.getMonthsBetween(start,end) 1
|
static int |
getSecond(Date date)
从日期中获取秒数
比如时间2014-05-12 22:10:00 DateCalcUtils.getSecond(date); 0
|
static long |
getTimeMillis(Date date)
获取时间的毫秒数,该毫秒是时间转换为毫秒,而不是日期时间中的转动的毫秒。
|
static int |
getYear(Date date)
从日期中获取年份
比如时间2014-05-12 12:10:00 DateCalcUtils.getYear(date); 2014
|
static boolean |
isLeapYear(Date date)
判断是否是闰年,闰年规则:闰年查看
比如时间2014-05-12 22:10:00 DateCalcUtils.isLeapYear(date); false
|
public static Date addMilliSecond(Date date, int milliSecond)
date - 日期milliSecond - 毫秒数Datepublic static Date addSecond(Date date, int seconds)
比如时间2014-05-12 12:00:00 DateCalcUtils.addSecond(date,2); 2014-05-12 12:00:02
比如时间2014-05-12 12:00:00 DateCalcUtils.addSecond(date,-2); 2014-05-12 11:59:58
date - 日期seconds - 秒,如果为正整数则添加,否则相减Datepublic static Date addMinute(Date date, int minutes)
比如时间2014-05-12 12:00:00 DateCalcUtils.addMinute(date,2); 2014-05-12 12:02:00
比如时间2014-05-12 12:00:00 DateCalcUtils.addMinute(date,-2); 2014-05-12 11:58:00
date - 日期minutes - 分钟,如果为正整数则添加,否则相减Datepublic static Date addHour(Date date, int hours)
比如时间2014-05-12 12:00:00 DateCalcUtils.addHour(date,1); 2014-05-12 13:00:00
比如时间2014-05-12 12:00:00 DateCalcUtils.addHour(date,-1); 2014-05-12 11:00:00
date - 日期hours - 小时,如果为正整数则添加,否则相减Datepublic static Date addDate(Date date, int day)
比如时间2014-05-12 12:00:00 DateCalcUtils.addDate(date,1); 2014-05-11 12:00:00
比如时间2014-05-12 12:00:00 DateCalcUtils.addDate(date,-1); 2014-05-13 12:00:00
date - 日期day - 天,如果为正整数则添加,否则相减Datepublic static Date addMonth(Date date, int months)
比如时间2014-05-12 12:10:00 DateCalcUtils.addMonth(date,1); 2014-06-12 12:10:00
比如时间2014-05-12 12:10:00 DateCalcUtils.addMonth(date,-1); 2014-04-12 12:10:00
date - 日期months - 月,如果为正整数则添加,否则相减Datepublic static Date addMonth(Date date, int months, boolean escapeDays)
比如时间2014-05-12 12:10:00 DateCalcUtils.addMonth(date,1,false); 2014-06-12 12:10:00
比如时间2014-05-12 12:10:00 DateCalcUtils.addMonth(date,1,true); 2014-06-01 00:00:00
date - 日期months - 月,如果为正整数则添加,否则相减escapeDays - 如果值为true则表示会清空时分秒毫秒,并且日期跳到当月的第一天;如果是false则不会Datepublic static Date addYear(Date date, int years)
比如时间2014-05-12 12:10:00 DateCalcUtils.addYear(date,1); 2015-06-12 12:10:00
比如时间2014-05-12 12:10:00 DateCalcUtils.addYear(date,-1); 2013-04-12 12:10:00
date - 日期years - 年,如果为正整数则添加,否则相减Datepublic static int getYear(Date date)
比如时间2014-05-12 12:10:00 DateCalcUtils.getYear(date); 2014
date - 日期对象public static int getMonth(Date date)
比如时间2014-05-12 12:10:00 DateCalcUtils.getMonth(date); 5
date - 日期对象public static int getDay(Date date)
比如时间2014-05-12 12:10:00 DateCalcUtils.getDay(date); 12
date - 日期对象public static int get24Hour(Date date)
比如时间2014-05-12 22:10:00 DateCalcUtils.get24Hour(date); 22
date - 日期对象public static int get12Hour(Date date)
比如时间2014-05-12 22:10:00 DateCalcUtils.get12Hour(date); 10
date - 日期对象public static int getMinute(Date date)
比如时间2014-05-12 22:10:00 DateCalcUtils.getMinute(date); 10
date - 日期对象public static int getSecond(Date date)
比如时间2014-05-12 22:10:00 DateCalcUtils.getSecond(date); 0
date - 日期对象public static int getMillisecond(Date date)
比如时间2014-05-12 22:10:00 DateCalcUtils.getMillisecond(date); 151
date - 日期对象public static long getTimeMillis(Date date)
比如时间2014-05-12 22:10:00 DateCalcUtils.getTimeMillis(date); 1402582200732L
date - 日期对象public static boolean isLeapYear(Date date)
比如时间2014-05-12 22:10:00 DateCalcUtils.isLeapYear(date); false
date - 日期对象public static Date getBeginDayInMonth(Date date)
比如时间2014-05-12 DateCalcUtils.getBeginDayInMonth("2014-05-12","yyyy-MM-dd"); 204-05-01
date - 日期public static Date getEndDayInMonth(Date date)
比如时间2014-05-12 DateCalcUtils.getEndDayInMonth(date); 204-05-31
date - 日期对象public static int getDaysBetween(Date start, Date end)
比如Date start = 2012-2-12
Date end = 2012-3-1
DateCalcUtils.getDaysBetween(start,end) 18
start - 日期对象end - 日期对象public static int getMonthsBetween(Date start, Date end)
比如Date start = 2012-2-12
Date end = 2012-3-1
DateCalcUtils.getMonthsBetween(start,end) 1
start - 日期对象end - 日期对象Copyright © 2017. All rights reserved.