public class DateUtil extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static long |
MILLISECONDS_FOR_ONE_DAY |
static long |
MILLISECONDS_FOR_ONE_HOUR |
static long |
MILLISECONDS_FOR_ONE_MINUTE |
static String |
MMDD_CHINESE |
static String |
YYYYMMDD |
static String |
YYYYMMDD_CHINESE |
static String |
YYYYMMDDHHMM_CHINESE |
static String |
YYYYMMDDHHMMSS |
static String |
YYYYMMDDHHMMSSSSS |
| 构造器和说明 |
|---|
DateUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static Date |
addSeconds(Integer seconds)
当前时间增加若干秒
|
static int |
calcIntervalDays(Date date1,
Date date2)
计算两个时间的间隔天数
|
static int |
calcIntervalDays(String dateStr1,
String dateStr2)
计算两个时间间隔的天数
|
static int |
calcIntervalMinutes(Date date1,
Date date2)
计算两个时间的间隔小时,只会整除
|
static int |
calcIntervalOurs(Date date1,
Date date2)
计算两个时间的间隔小时,只会整除
|
static String |
dateToShortDateString(Date date) |
static String |
dateToString(Date date,
String format) |
static String |
dateToVoString(Date date)
全站时间展示规范
1分钟内:刚刚
超过1分钟并在1小时内:某分钟前 (1分钟前)
超过1小时并在当日内:某小时前(1小时前)
昨天:昨天 + 小时分钟(昨天 08:30)
昨天之前并在当年内:某月某日 + 小时分钟(1月1日 08:30)
隔年:某年某月某日 + 小时分钟(2015年1月1日 08:30)
|
static int |
dayOfWeek(Date date)
返回日期对应的是星期几
|
static Date |
endTime(Date time)
获取传入当日最后一刻
|
static Date |
getCurrentDate() |
static int |
getDay(Date date)
获取日期
|
static Date |
getIntervalDaysDate(Date time,
int days)
获取指定间隔天数的日期
|
static Date |
getIntervalHourDate(Date time,
int hours)
获取间隔的几个小时,如需要获取之前的3小时,hours传-3
|
static int |
getMonth(Date date)
获取月份
|
static int |
getMonthFirstDay(int year,
int month)
获取某月的第一天
|
static int |
getMonthLastDay(int year,
int month)
获取某月的最后一天
|
static Date |
getNow() |
static Float |
getPercentage(Date date)
获取指定日期百分百
|
static int |
getTodayMinutes()
获取今天的分钟数,如今天18:05,则返回1805
|
static int |
getYear(Date date)
获取年份
|
static boolean |
isLeap(int year)
判断是否是闰年
|
static boolean |
isSameDay(Date date1,
Date date2)
比较两个时间是否是相同的天数
|
static Date |
startTime(Date time)
获取传入当日0点
|
static Date |
stringToDate(String dateStr)
将String转成Date,默认时区东八区,TimeZone.getTimeZone("Asia/Shanghai")
|
static Calendar |
toCalendar(Date date)
将Date转成Calendar
|
public static final long MILLISECONDS_FOR_ONE_MINUTE
public static final long MILLISECONDS_FOR_ONE_HOUR
public static final long MILLISECONDS_FOR_ONE_DAY
public static Date getCurrentDate()
public static int dayOfWeek(Date date)
public static int getTodayMinutes()
public static Date getIntervalHourDate(Date time, int hours)
public static Date stringToDate(String dateStr)
dateStr - 含格式的时间字符串串public static String dateToVoString(Date date)
public static int getYear(Date date)
date - public static int getMonth(Date date)
date - public static int getDay(Date date)
date - public static int getMonthLastDay(int year,
int month)
year - month - public static int getMonthFirstDay(int year,
int month)
year - month - public static boolean isLeap(int year)
year - public static Date getNow()
Copyright © 2020. All rights reserved.