public class DateUtils
extends java.lang.Object
| 构造器和说明 |
|---|
DateUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static java.util.Date |
addDays(java.util.Date date,
int amount)
Adds a number of days to a date returning a new object.
|
static java.util.Date |
addHours(java.util.Date date,
int amount)
Adds a number of hours to a date returning a new object.
|
static java.util.Date |
addMilliseconds(java.util.Date date,
int amount)
Adds a number of milliseconds to a date returning a new object.
|
static java.util.Date |
addMinutes(java.util.Date date,
int amount)
Adds a number of minutes to a date returning a new object.
|
static java.util.Date |
addMonths(java.util.Date date,
int amount)
Adds a number of months to a date returning a new object.
|
static java.util.Date |
addSeconds(java.util.Date date,
int amount)
Adds a number of seconds to a date returning a new object.
|
static java.util.Date |
addWeeks(java.util.Date date,
int amount)
Adds a number of weeks to a date returning a new object.
|
static java.util.Date |
addYears(java.util.Date date,
int amount)
Adds a number of years to a date returning a new object.
|
static long |
diffSeconds(java.util.Date date1,
java.util.Date date2)
计算两个Date对象之间相差多少秒.
|
static boolean |
isSameDay(java.util.Calendar cal1,
java.util.Calendar cal2)
Checks if two calendar objects are on the same day ignoring time.
|
static boolean |
isSameDay(java.util.Date date1,
java.util.Date date2)
判断两个日期时间是否是同一天 。
|
static boolean |
isSameMonth(java.util.Calendar cal1,
java.util.Calendar cal2)
判定两个日期是否为同年同月份
|
static boolean |
isSameMonth(java.util.Date date1,
java.util.Date date2)
判断两个日期时间是否是同年同月份
|
static boolean |
isSameWeek(java.util.Calendar cal1,
java.util.Calendar cal2)
判定两个日期是否为同周
|
static boolean |
isSameWeek(java.util.Date date1,
java.util.Date date2)
判断两个日期时间是否是同周
|
static long |
toSeconds(java.util.Date date)
将Date对象转化为秒数.
|
public static boolean isSameDay(java.util.Date date1,
java.util.Date date2)
date1 - 第一个日期date2 - 第二个日期public static boolean isSameDay(java.util.Calendar cal1,
java.util.Calendar cal2)
Checks if two calendar objects are on the same day ignoring time.
28 Mar 2002 13:45 and 28 Mar 2002 06:01 would return true. 28 Mar 2002 13:45 and 12 Mar 2002 13:45 would return false.
cal1 - the first calendar, not altered, not nullcal2 - the second calendar, not altered, not nulljava.lang.IllegalArgumentException - if either calendar is nullpublic static boolean isSameWeek(java.util.Date date1,
java.util.Date date2)
date1 - 第一个日期date2 - 第二个日期public static boolean isSameWeek(java.util.Calendar cal1,
java.util.Calendar cal2)
cal1 - 第一个日期cal2 - 第二个日期public static boolean isSameMonth(java.util.Date date1,
java.util.Date date2)
date1 - 第一个日期date2 - 第二个日期public static boolean isSameMonth(java.util.Calendar cal1,
java.util.Calendar cal2)
cal1 - 第一个日期cal2 - 第二个日期public static java.util.Date addYears(java.util.Date date,
int amount)
Date is unchanged.date - the date, not nullamount - the amount to add, may be negativeDate with the amount addedjava.lang.IllegalArgumentException - if the date is nullpublic static java.util.Date addMonths(java.util.Date date,
int amount)
Date is unchanged.date - the date, not nullamount - the amount to add, may be negativeDate with the amount addedjava.lang.IllegalArgumentException - if the date is nullpublic static java.util.Date addWeeks(java.util.Date date,
int amount)
Date is unchanged.date - the date, not nullamount - the amount to add, may be negativeDate with the amount addedjava.lang.IllegalArgumentException - if the date is nullpublic static java.util.Date addDays(java.util.Date date,
int amount)
Date is unchanged.date - the date, not nullamount - the amount to add, may be negativeDate with the amount addedjava.lang.IllegalArgumentException - if the date is nullpublic static java.util.Date addHours(java.util.Date date,
int amount)
Date is unchanged.date - the date, not nullamount - the amount to add, may be negativeDate with the amount addedjava.lang.IllegalArgumentException - if the date is nullpublic static java.util.Date addMinutes(java.util.Date date,
int amount)
Date is unchanged.date - the date, not nullamount - the amount to add, may be negativeDate with the amount addedjava.lang.IllegalArgumentException - if the date is nullpublic static java.util.Date addSeconds(java.util.Date date,
int amount)
Date is unchanged.date - the date, not nullamount - the amount to add, may be negativeDate with the amount addedjava.lang.IllegalArgumentException - if the date is nullpublic static java.util.Date addMilliseconds(java.util.Date date,
int amount)
Date is unchanged.date - the date, not nullamount - the amount to add, may be negativeDate with the amount addedjava.lang.IllegalArgumentException - if the date is nullpublic static long toSeconds(java.util.Date date)
为了代码里不要到处出现的情况Date.getTime() / 1000
date - Date日期public static long diffSeconds(java.util.Date date1,
java.util.Date date2)
date1 - 时间一date2 - 时间二