public class DateUtils extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
DATE_FORMAT
默认格式
|
static String |
DATE_TIME_FORMAT
时间
|
| 构造器和说明 |
|---|
DateUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static long |
getAge(String bothday,
String format)
根据输入生日获取年龄
|
static String |
getBeforeOrAfterNumberDateFromInputDate(String dateStr,
String inputFormat,
String outputFormat,
int n)
获取当前日期的前/后n天的日期字符串; n为负数,则表示前n天,正数后n天
|
static String |
getCurrentDate(String format)
获取当前系统时间或日期(任意格式)
|
static Date |
getDateEnd(Date end)
获取日期结束时间(一般用于区间查询)
|
static Date |
getDateStart(Date start)
获取日期开始时间(一般用于时间查询)
|
static long |
getMillisecondNow()
1970 年 1 月 1 日开始计算到 Date 当前对象中的时间之间的毫秒
|
static String |
getSecondsToHHMMSS(int second)
整数的秒转换为:HH:MM:SS格式时间
|
static boolean |
isTimeHour(String h)
判断输入的一个字符是否为有效的时间-小时
|
static boolean |
isTimeMinute(String m)
判断输入的一个字符是否未有效时间-分钟
|
static boolean |
isTimeSecond(String s)
判断输入的一个字符是否未有效时间-秒
|
static String |
parseDate2String(Date date,
String format)
将一个date类型日期转换为指定格式的字符串日期
|
static Date |
parseString2Date(String dateStr,
String format)
转换字符串日期为java Date对象日期
|
static String |
parseStringDateFormat(String date,
String srcFormat,
String destFormat)
字符串字符串日期格式转换
|
static Date |
plusDay(Date date,
int num)
加 日
|
static Date |
plusHour(Date date,
int num) |
static Date |
plusMinute(Date date,
int num) |
static Date |
plusMonth(Date date,
int num) |
static Date |
plusYear(Date date,
int num) |
public static String parseDate2String(Date date, String format)
date - 源日期format - 格式public static Date parseString2Date(String dateStr, String format) throws ParseException
dateStr - 字符串日期format - 格式 如:yyyy-MM-dd HH:mm:ssParseExceptionpublic static String getCurrentDate(String format)
format - 想要获取到的日期或时间格式public static String parseStringDateFormat(String date, String srcFormat, String destFormat) throws ParseException
date - 源字符串日期srcFormat - 源字符串日期格式destFormat - 输出字符串日期格式ParseException - 转换异常public static String getBeforeOrAfterNumberDateFromInputDate(String dateStr, String inputFormat, String outputFormat, int n) throws ParseException
dateStr - 输入指定日期inputFormat - 输入日期格式outputFormat - 输出日期格式n - 天数ParseException - 转换异常public static String getSecondsToHHMMSS(int second)
second - 输入参数,秒钟public static boolean isTimeHour(String h)
h - 输入参数-小时public static boolean isTimeMinute(String m)
m - 输入参数-分钟public static boolean isTimeSecond(String s)
s - 输入参数-秒public static long getMillisecondNow()
public static long getAge(String bothday, String format) throws ParseException
bothday - 生日format - 时间格式ParseException - 转换异常public static Date getDateStart(Date start)
start - 日期public static Date getDateEnd(Date end)
end - 日期Copyright © 2022. All rights reserved.