public class DateUtils
extends java.lang.Object
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
HOUR_PER_DAY
每天有24小时
|
static int |
MILLISECOND_PER_SECOND
每秒有1000毫秒
|
static int |
MINUTE_PER_HOUR
每小时有60分钟
|
static int |
SECOND_PER_MINUTE
每分钟有60秒
|
| 构造器和说明 |
|---|
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 |
diffDays(java.util.Date date1,
java.util.Date date2)
计算两个Date对象之间相差多少天.
|
static long |
diffSeconds(java.util.Date date1,
java.util.Date date2)
计算两个Date对象之间相差多少秒.
|
static java.lang.String |
formatTime(long seconds)
将一个秒数格式化为一个时间格式 HH:mm:ss
游戏中规则显示,用于格式参数等格式秒数
|
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 |
toDays(java.util.Date date)
将Date对象转化为天数.
|
static long |
toDays(long milliseconds)
将毫秒数转化为天数.
|
static long |
toSeconds(java.util.Date date)
将Date对象转化为秒数.
|
static long |
toSeconds(long milliseconds)
将毫秒数转化为秒数.
|
static long |
toSecondsByStartOfDay(java.time.LocalDate localDate)
获取指定日期那天的开始时间并转化为秒数
|
public static final int MILLISECOND_PER_SECOND
public static final int SECOND_PER_MINUTE
public static final int MINUTE_PER_HOUR
public static final int HOUR_PER_DAY
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 toSeconds(long milliseconds)
为了代码里不要到处出现的情况Date.getTime() / 1000
milliseconds - 毫秒数public static long toSecondsByStartOfDay(java.time.LocalDate localDate)
localDate - 指定日期public static long toDays(java.util.Date date)
date - Date日期public static long toDays(long milliseconds)
milliseconds - 毫秒数public static long diffSeconds(java.util.Date date1,
java.util.Date date2)
date1 - 时间一date2 - 时间二public static long diffDays(java.util.Date date1,
java.util.Date date2)
由于使用毫秒计算的方式,所以计算天数需要处理时区问题...
date1 - 时间一date2 - 时间二public static java.lang.String formatTime(long seconds)
游戏中规则显示,用于格式参数等格式秒数
seconds - 一个毫秒数