public class DateUtils extends Object
| 构造器和说明 |
|---|
DateUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static long |
between(Date date1,
Date date2,
CalendarFieldEnum field)
获取两个日期之间的时间差
|
static long |
between(Date date1,
Date date2,
int field)
获取两个日期之间的时间差
|
static long |
betweenDay(Date date1,
Date date2)
获取两个日期之间的天数
|
static long |
betweenHour(Date date1,
Date date2)
获取两个日期之间的小时数
|
static long |
betweenMilliSecond(Date date1,
Date date2)
获取两个日期之间的毫秒数
|
static long |
betweenMinute(Date date1,
Date date2)
获取两个日期之间的分钟数
|
static long |
betweenSecond(Date date1,
Date date2)
获取两个日期之间的秒数
|
static int |
compare(Date date1,
Date date2)
比较两个日期
0:相等
1:date1大于date2
-1:date1小于date2
0:date1或date2为空
|
static Date |
create()
创建当前时间
|
static Date |
create(int year,
int month,
int day,
int hour,
int minute,
int second)
已过时。
|
static Date |
create(long time)
创建指定时间
|
static Calendar |
createCalendar()
创建日历时间
|
static Calendar |
createCalendar(TimeZone timeZone)
创建日历时间
|
static Calendar |
createCalendar(java.time.ZoneId zoneId)
创建日历时间
|
static Calendar |
createCalendar(ZoneIdEnum zoneId)
创建日历时间
|
static Date |
createDate(int year,
int month,
int day)
创建指定时间
|
static Date |
createDate(int year,
int month,
int day,
int hour,
int minute)
创建指定时间
|
static Date |
createDate(int year,
int month,
int day,
int hour,
int minute,
int second)
创建指定时间
|
static Date |
createDate(int year,
int month,
int day,
int hour,
int minute,
int second,
int millisecond)
创建指定时间
|
static long |
dateToTimestamp(Date date)
日期 转为 时间戳
|
static String |
format(Date date)
格式化日期
|
static String |
format(Date date,
String format)
格式化日期
|
static String |
format(Date date,
String format,
Locale locale)
格式化日期
|
static String |
format(Date date,
String format,
Locale locale,
TimeZone timeZone)
格式化日期
|
static int |
get(Date date,
CalendarFieldEnum field)
获取日期
|
static int |
get(Date date,
int field)
获取日期
|
static int |
getDay()
获取日期
|
static int |
getDay(Date date)
获取日期
|
static int |
getHour()
获取小时
|
static int |
getHour(Date date)
获取小时
|
static int |
getMilliSecond()
获取毫秒
|
static int |
getMilliSecond(Date date)
获取毫秒
|
static int |
getMinute()
获取分钟
|
static int |
getMinute(Date date)
获取分钟
|
static int |
getMonth()
获取月份
|
static int |
getMonth(Date date)
获取月份
|
static String |
getNowFormat()
获取当前格式化日期
|
static String |
getNowFormat(String format)
获取当前格式化日期
|
static String |
getNowPath()
获取当前日期路径
|
static String |
getNowPath(String format)
获取当前日期路径
|
static String |
getNowPath(String format,
String suffix)
获取当前日期路径
|
static int |
getSecond()
获取秒
|
static int |
getSecond(Date date)
获取秒
|
static int |
getYear()
获取当前年份
|
static int |
getYear(Date date)
获取年份
|
static boolean |
isAfter(Date date1,
Date date2)
前一个日期是否在后一个日期之后
|
static boolean |
isBefore(Date date1,
Date date2)
前一个日期是否在后一个日期之前
|
static boolean |
isSameDay(Date date1,
Date date2)
比较两个日期
|
static Date |
move(Date date,
CalendarFieldEnum field,
int amount)
移动时间
Calendar.YEAR 年
Calendar.MONTH 月
Calendar.DAY_OF_MONTH 日
Calendar.HOUR 时
Calendar.HOUR_OF_DAY 时
Calendar.MINUTE 分
Calendar.SECOND 秒
Calendar.MILLISECOND 毫秒
Calendar.WEEK_OF_YEAR 周
Calendar.DAY_OF_YEAR 天
Calendar.DAY_OF_WEEK 星期
Calendar.DAY_OF_WEEK_IN_MONTH 星期
Calendar.AM_PM 上午/下午
Calendar.ZONE_OFFSET 时区
Calendar.DST_OFFSET 夏令时
Calendar.ERA 时代
|
static Date |
move(Date date,
int field,
int amount)
移动时间
Calendar.YEAR 年
Calendar.MONTH 月
Calendar.DAY_OF_MONTH 日
Calendar.HOUR 时
Calendar.HOUR_OF_DAY 时
Calendar.MINUTE 分
Calendar.SECOND 秒
Calendar.MILLISECOND 毫秒
Calendar.WEEK_OF_YEAR 周
Calendar.DAY_OF_YEAR 天
Calendar.DAY_OF_WEEK 星期
Calendar.DAY_OF_WEEK_IN_MONTH 星期
Calendar.AM_PM 上午/下午
Calendar.ZONE_OFFSET 时区
Calendar.DST_OFFSET 夏令时
Calendar.ERA 时代
|
static Date |
now()
获取当前时间
|
static long |
timestamp()
获取当前时间戳
|
static int |
timestamp10()
获取当前时间戳
10位
|
static long |
timestamp13()
获取当前时间戳
13位
|
static long |
timestampTen()
获取当前时间戳
10位
|
static Date |
timestampToDate(long timestamp)
时间戳 转为 日期
时间戳为10位时,自动转为13位
|
public static Date now()
public static Date create()
public static Date create(long time)
time - 指定时间@Deprecated public static Date create(int year, int month, int day, int hour, int minute, int second)
year - 年month - 月day - 日hour - 时minute - 分second - 秒public static Date createDate(int year, int month, int day)
year - 年month - 月day - 日public static Date createDate(int year, int month, int day, int hour, int minute)
year - 年month - 月day - 日hour - 时minute - 分public static Date createDate(int year, int month, int day, int hour, int minute, int second)
year - 年month - 月day - 日hour - 时minute - 分second - 秒public static Date createDate(int year, int month, int day, int hour, int minute, int second, int millisecond)
year - 年month - 月day - 日hour - 时minute - 分second - 秒millisecond - 毫秒public static Calendar createCalendar()
public static Calendar createCalendar(TimeZone timeZone)
timeZone - 时区public static Calendar createCalendar(java.time.ZoneId zoneId)
zoneId - 时区public static Calendar createCalendar(ZoneIdEnum zoneId)
zoneId - 时区public static Date move(Date date, int field, int amount)
Calendar.YEAR 年 Calendar.MONTH 月 Calendar.DAY_OF_MONTH 日 Calendar.HOUR 时 Calendar.HOUR_OF_DAY 时 Calendar.MINUTE 分 Calendar.SECOND 秒 Calendar.MILLISECOND 毫秒 Calendar.WEEK_OF_YEAR 周 Calendar.DAY_OF_YEAR 天 Calendar.DAY_OF_WEEK 星期 Calendar.DAY_OF_WEEK_IN_MONTH 星期 Calendar.AM_PM 上午/下午 Calendar.ZONE_OFFSET 时区 Calendar.DST_OFFSET 夏令时 Calendar.ERA 时代
date - 时间field - 字段amount - 数量public static Date move(Date date, CalendarFieldEnum field, int amount)
Calendar.YEAR 年 Calendar.MONTH 月 Calendar.DAY_OF_MONTH 日 Calendar.HOUR 时 Calendar.HOUR_OF_DAY 时 Calendar.MINUTE 分 Calendar.SECOND 秒 Calendar.MILLISECOND 毫秒 Calendar.WEEK_OF_YEAR 周 Calendar.DAY_OF_YEAR 天 Calendar.DAY_OF_WEEK 星期 Calendar.DAY_OF_WEEK_IN_MONTH 星期 Calendar.AM_PM 上午/下午 Calendar.ZONE_OFFSET 时区 Calendar.DST_OFFSET 夏令时 Calendar.ERA 时代
date - 时间field - 字段amount - 数量public static int compare(Date date1, Date date2)
0:相等 1:date1大于date2 -1:date1小于date2 0:date1或date2为空
date1 - 日期1date2 - 日期2public static boolean isSameDay(Date date1, Date date2)
date1 - 日期1date2 - 日期2public static boolean isBefore(Date date1, Date date2)
date1 - 日期1date2 - 日期2public static boolean isAfter(Date date1, Date date2)
date1 - 日期1date2 - 日期2public static long betweenDay(Date date1, Date date2)
date1 - 日期1date2 - 日期2public static long betweenHour(Date date1, Date date2)
date1 - 日期1date2 - 日期2public static long betweenMinute(Date date1, Date date2)
date1 - 日期1date2 - 日期2public static long betweenSecond(Date date1, Date date2)
date1 - 日期1date2 - 日期2public static long betweenMilliSecond(Date date1, Date date2)
date1 - 日期1date2 - 日期2public static long between(Date date1, Date date2, CalendarFieldEnum field)
date1 - 日期1date2 - 日期2field - 字段public static long between(Date date1, Date date2, int field)
date1 - 日期1date2 - 日期2field - 字段public static int getYear(Date date)
date - 日期public static int getMonth(Date date)
date - 日期public static int getDay(Date date)
date - 日期public static int getHour(Date date)
date - 日期public static int getMinute(Date date)
date - 日期public static int getSecond(Date date)
date - 日期public static int getMilliSecond(Date date)
date - 日期public static int get(Date date, CalendarFieldEnum field)
date - 日期field - 字段public static int get(Date date, int field)
date - 日期field - 字段public static int getYear()
public static int getMonth()
public static int getDay()
public static int getHour()
public static int getMinute()
public static int getSecond()
public static int getMilliSecond()
public static String getNowPath()
public static String getNowPath(String format, String suffix)
format - 格式suffix - 后缀public static Date timestampToDate(long timestamp)
时间戳为10位时,自动转为13位
timestamp - 时间戳public static long dateToTimestamp(Date date)
date - 日期public static long timestamp()
public static int timestamp10()
public static long timestampTen()
public static long timestamp13()
public static String getNowFormat()
public static String format(Date date, String format)
date - 日期format - 格式public static String format(Date date, String format, Locale locale)
date - 日期format - 格式locale - 本地化Copyright © 2024. All rights reserved.