public final class DateUtil extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
DATE_FORMAT
日期格式化
|
static String |
DATE_TIME_FORMAT
简单的日期时间格式化
|
static String |
DATE_TIME_SEC_FORMAT
简单的日期时间格式化
|
static String |
DATE_ZH_FORMAT
日期格式化
|
static String |
PURE_DATE_FORMAT
纯净日期格式化
|
static String |
PURE_TIME_FORMAT
纯净时间格式化
|
static String |
TIME_FORMAT
时间格式化
|
static String |
TIME_ZH_FORMAT
时间格式化
|
static String |
TIMESTAMP_FORMAT_14
时间戳格式化
14位长度
|
static String |
TIMESTAMP_FORMAT_15
时间戳格式化(15 位长度)
备注:因为 2019 最前面两位,在自己的有生之年,基本是不变的。
|
static String |
TIMESTAMP_FORMAT_17
时间戳格式化
17位长度
|
| 限定符和类型 | 方法和说明 |
|---|---|
static Date |
addDay(Date date,
int day)
日变更
|
static Date |
addHour(Date date,
int hour)
分钟变更
|
static Date |
addMinute(Date date,
int minute)
分钟变更
|
static Date |
addMonth(Date date,
int month)
月份变更
|
static Date |
addSecond(Date date,
int second)
秒变更
|
static Date |
addYear(Date date,
int year)
年份变更
|
static String |
changeFormat(String dateOld,
String oldFormat,
String newFormat)
变化格式
|
static long |
convertMsToNs(long ms)
毫秒转化为纳秒
1.
|
static long |
costTimeInMills(Date start,
Date end)
计算消耗的毫秒
|
static String |
formatDate(Date date,
String format)
格式化日期
|
static Date |
fromSql(Date date)
从 sql 转化为 date
|
static Date |
getCurrentDate()
获取当前日期
|
static int |
getCurrentDateHours()
获取当前日期的小时数
|
static String |
getCurrentDatePureStr()
获取日期当前字符串形式
|
static String |
getCurrentDateStr()
获取日期当前字符串形式
|
static String |
getCurrentDateTimeStr()
获取当前日期时间字符串
|
static String |
getCurrentTime14()
获取当前时间戳。
|
static String |
getCurrentTime17()
获取当前时间戳。
|
static String |
getCurrentTimeMills()
当前的毫秒数
|
static String |
getCurrentTimeStampStr()
获取当前时间戳。
|
static String |
getCurrentTimeStampStr15()
获取当前时间戳。
|
static String |
getDateFormat(Date date,
String format)
获取格式化的日期
|
static String |
getDateFormat14(Date date)
格式化为 14 位时间戳
|
static String |
getDateFormat17(Date date)
格式化为 17 位时间戳
|
static Integer |
getDateHours(Date date)
获取日期的小时
|
static List<Date> |
getDateRangeList(Date startDate,
Date endDate)
获取日期列表
|
static List<String> |
getDateRangeList(String begin,
String end)
获取两个日期中的所有日期,并转换为表后缀
|
static String |
getDifferDate(Date date,
int differ)
获取差异的时间
|
static long |
getDistanceDays(Date one,
Date two)
获取相差的天数
|
static long |
getDistanceDays(String str1,
String str2)
两个时间之间相差距离多少天
|
static Date |
getFormatDate(String dateStr,
String format)
对字符串格式化为日期
|
static Date |
getFormatDate14(String dateStr)
对字符串格式化为日期
|
static Date |
getFormatDate17(String dateStr)
对字符串格式化为日期
|
static String |
getYesterdayPureStr()
获取日期当前字符串形式
|
static boolean |
isAm()
是否为早晨
|
static boolean |
isPm()
是否为下午
|
static Date |
now()
返回当前时间
|
static Date |
parseDate(String string,
String format)
对日期进行转换
|
static void |
sleep(long pauseMills)
当前线程主动沉睡
|
static void |
sleep(TimeUnit unit,
long timeout)
当前线程主动沉睡
|
static String |
slimDate(String yyyyMMddStr)
日期缩短
12.25
3.25
|
static Date |
toDate(Calendar calendar)
日历转日期
|
static Date |
toDate(Object object)
对象转 Date
|
static Date |
toSqlDate(Date date)
从 date 转化为 sql date
|
static Time |
toSqlTime(Date date)
从 date 转化为 sql date
|
static Timestamp |
toSqlTimestamp(Date date)
从 date 转化为 sql date
|
public static final String DATE_TIME_SEC_FORMAT
public static String getDateFormat(Date date, String format)
date - 日期format - 格式化public static String formatDate(Date date, String format)
date - 日期format - 格式化public static Date parseDate(String string, String format)
string - 字符串format - 格式public static String getDateFormat17(Date date)
date - 日期public static String getDateFormat14(Date date)
date - 日期public static Date getFormatDate(String dateStr, String format)
dateStr - 日期字符串format - 格式化public static Date getFormatDate17(String dateStr)
dateStr - 日期字符串public static Date getFormatDate14(String dateStr)
dateStr - 日期字符串public static String getCurrentDateStr()
public static String getCurrentDatePureStr()
public static String getYesterdayPureStr()
public static String getCurrentTimeStampStr()
public static String getCurrentTime17()
public static String getCurrentTime14()
public static String getCurrentTimeStampStr15()
public static String getCurrentTimeMills()
public static String getCurrentDateTimeStr()
public static long convertMsToNs(long ms)
ms - 毫秒public static Date now()
public static long costTimeInMills(Date start, Date end)
start - 开始时间end - 结束时间public static void sleep(long pauseMills)
pauseMills - 暂定的毫秒数public static void sleep(TimeUnit unit, long timeout)
unit - 时间单位timeout - 超时时间public static Date toSqlDate(Date date)
date - 日期public static Time toSqlTime(Date date)
date - 日期public static Timestamp toSqlTimestamp(Date date)
date - 日期public static Date addYear(Date date, int year)
date - 日期year - 年份public static Date addMonth(Date date, int month)
date - 日期month - 月份public static Date addDay(Date date, int day)
date - 日期day - 日public static Date addHour(Date date, int hour)
date - 日期hour - 时public static Date addMinute(Date date, int minute)
date - 日期minute - 分public static Date addSecond(Date date, int second)
date - 日期second - 秒public static Date getCurrentDate()
public static Integer getDateHours(Date date)
date - 日期public static int getCurrentDateHours()
public static boolean isAm()
public static boolean isPm()
public static String slimDate(String yyyyMMddStr)
yyyyMMddStr - 原始格式public static List<String> getDateRangeList(String begin, String end)
begin - 格式:yyyyMMddend - 格式:yyyyMMddpublic static List<Date> getDateRangeList(Date startDate, Date endDate)
startDate - 开始日期endDate - 结束日期public static String getDifferDate(Date date, int differ)
date - 日期differ - 差异public static String changeFormat(String dateOld, String oldFormat, String newFormat)
dateOld - 原始日期oldFormat - 原始格式newFormat - 新格式public static long getDistanceDays(String str1, String str2)
str1 - 时间参数 1 yyyyMMddstr2 - 时间参数 2 yyyyMMddpublic static long getDistanceDays(Date one, Date two)
one - 日期1two - 日期2Copyright © 2024. All rights reserved.