Package com.luna.common.date
Class DateUtils
java.lang.Object
com.luna.common.date.DateUtils
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final java.time.format.DateTimeFormatterstatic final java.time.format.DateTimeFormatterstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final java.time.format.DateTimeFormatterstatic final String兼容不规范的iso8601时间格式static final String用以输出标准的iso8601时间格式static final java.time.format.DateTimeFormatterstatic final Stringstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Datestatic Datestatic DateaddMinutes(Date date, int amount) static Datestatic DateaddSeconds(Date date, int amount) static Datestatic Datestatic StringappendTime(String date) static long判断两个日期相差的时长
返回 给定单位的时长差static DateconvertToDate(java.time.temporal.TemporalAccessor temporalAccessor, java.time.ZoneId zoneId) 将 TemporalAccessor 转换为 DatedateBetween(Long startDate, Long endDate, Long interval) 获取两个时间直接指定间隔天数列表static StringdatePath()日期路径 即年/月/日 如2018/08/08static booleanstatic String毫秒数转为字符串 按照指定格式转换static String返回自定义格式字符串static StringformatDate(long time) 返回自字符串格式为:yyyy-MM-ddstatic StringformatDate(Date aDate) 返回自字符串格式为:yyyy-MM-ddstatic StringformatDateMonth(Long time) 返回自字符串格式为:yyyy-MMstatic StringformatDateMonth(Date aDate) 返回自字符串格式为:yyyy-MMstatic StringformatDateTime(long time) 返回自字符串格式为:yyyy-MM-dd HH:mm:ssstatic StringformatDateTime(Date date) 返回自字符串格式为:yyyy-MM-dd HH:mm:ssstatic StringformatDateTimeStr(long time) 返回自字符串格式为:yyyyMMddHHmmssSSSstatic StringformatDateTimeStr(Date date) 返回自字符串格式为:yyyyMMddHHmmssSSSstatic StringformatTime(long time) 返回自字符串格式为:HH:mm:ssstatic StringformatTime(String aMask, java.time.temporal.TemporalAccessor aDate) 将localTime + 时区 转为UTC时间 返回自定义格式字符串static StringformatTime(String aMask, Date date) 返回自定义格式字符串static StringformatTime(Date date) 返回自字符串格式为:HH:mm:ssgetBetweenWithDay(Date startDate, Date endDate) 获取间隔 1 天 的时间列表getBetweenWithMonth(Date startDate, Date endDate) 获取间隔 1月 (30.44 天) 的时间列表getBetweenWithWeek(Date startDate, Date endDate) 获取间隔 1 周 的时间列表getBetweenWithYear(Date startDate, Date endDate) 获取间隔 1年 (365.24 天) 的时间列表static Datestatic long获取当前时间戳,单位秒static long获取当前时间戳,单位毫秒static DategetDateEnd(String dateStr) 获取日期的结束时间static StringgetDatePoor(Date endDate, Date nowDate) 计算两个时间差static DategetDateStart(String dateStr) 获取日期的开始时间static longgetDaysBetween(Date beginDate, Date endDate) 得两个日期之间的相差多少天static longgetHalfYearEndStamp(Date date) 获取前/后半年的结束时间static DategetHalfYearEndTime(Date date) 获取前/后半年的结束时间static longgetHalfYearStartStamp(Date date) 获取前/后半年的开始时间static DategetHalfYearStartTime(Date date) 获取前/后半年的开始时间static DategetLastDateTimeOfMonth(Date date) 获得某月的最后一天的最后时间static longgetLastStampOfMonth(Date date) 获得某月的最后一天的最后时刻static DategetMonthBeginDateTime(Date date) 获取指定时间当月0点毫秒时间static long获取当月0点毫秒时间static longgetMonthBeginStamp(Date date) 获取指定时间当月0点毫秒时间static long获取当月月底毫秒时间static DategetMorning(Date date) 获取凌晨00:00:00static StringgetMorningStr(Date date) 获取给定日期0点时间的字符串static Date获得 某天的23:59:59static StringgetNightStr(Date date) 获取给定日期23.59.59秒的时间字符串static longgetQuarterEndStamp(Date date) 当前季度的结束时间static DategetQuarterEndTime(Date date) 当前季度的结束时间static longgetQuarterStartStamp(Date date) 当前季度的开始时间static DategetQuarterStartTime(Date date) 当前季度的开始时间static Date获取服务器启动时间static StringgetTimeInteval(Date date) static Stringstatic intgetWeekDay(Date date) 根据日期取得星期几 weekIndex = 0 表示星期日,依次类推static longgetWeekDayEndStamp(Date date) 获得本周的最后一天,周日static DategetWeekDayEndTime(Date date) 获得本周的最后一天,周日static DayWeekEnumgetWeekDayEnum(Date date) static longgetWeekDayStartStamp(Date date) 获得本周的第一天,周一static DategetWeekDayStartTime(Date date) 获得本周的第一天,周一static intgetWeekOfYear(Date date) 取得日期是某年的第几周static intstatic intstatic longgetYearEndStamp(Date date) 当前年的结束时间static DategetYearEndTime(Date date) 当前年的结束时间static longgetYearStartStamp(Date date) 当前年的开始时间static DategetYearStartTime(Date date) 当前年的开始时间static booleanisDayOfMonth(Date date, int day) date是否是给定的第x天static booleanisLeapYear(int year) 是否闰年static boolean判断两个时间段是否有重叠static Stringstatic Date年4位,月、日、时、分、秒各2位,毫秒3位,支持从右边删除任意部分,如:只有年月日,或者只有年月等static Date支持自定义格式转换static Date只支持格式yyyy-MM-ddstatic DateparseDateDay(String strDate) 只支持格式yyMMddstatic DateparseDateMonth(String strDate) 只支持格式yyyy-MMstatic DateparseDateTime(String strDate) 只支持格式yyyy-MM-dd HH:mm:ssstatic Date只支持格式HH:mm:ssstatic Datestatic java.time.temporal.TemporalAccessorparseTimeSd(String aMask, String strDate) 获取日期所属季度开始结束时间quarterTime(Date date) 获取当前日期所属季度开始结束时间static DatesetWeekDay(Date date, int weekIndex) 设置日期到那一周的周几,weekIndex = 0 表示星期日,依次类推static intthisYear()当前年份
-
Field Details
-
ISO8601_COMPATIBLE_PATTERN
兼容不规范的iso8601时间格式- See Also:
-
ISO8601_PATTERN
用以输出标准的iso8601时间格式- See Also:
-
ZONE_STR
- See Also:
-
FORMAT_YYYY_MM_DD
- See Also:
-
FORMAT_YYYY_MM
- See Also:
-
FORMAT_YYYY_MM_DD_HH_MM_SS
- See Also:
-
FORMAT_YYYY_MM_DD_HH_MM
- See Also:
-
FORMAT_HH_MM_SS
- See Also:
-
FORMAT_YYYYMMDD
- See Also:
-
FORMAT_YYYYMMDDHHMMSS
- See Also:
-
FORMAT_CHINESE
- See Also:
-
FORMAT_HH_MM
- See Also:
-
FORMAT_YMDHMS
- See Also:
-
START_TIME
- See Also:
-
END_TIME
- See Also:
-
ISO8601_COMPATIBLE_FORMAT
public static final java.time.format.DateTimeFormatter ISO8601_COMPATIBLE_FORMAT -
ISO8601_PATTERN_FORMAT
public static final java.time.format.DateTimeFormatter ISO8601_PATTERN_FORMAT -
DATETIME
public static final java.time.format.DateTimeFormatter DATETIME -
DATE
public static final java.time.format.DateTimeFormatter DATE
-
-
Constructor Details
-
DateUtils
public DateUtils()
-
-
Method Details
-
formatDateMonth
返回自字符串格式为:yyyy-MM -
formatDate
返回自字符串格式为:yyyy-MM-dd -
formatDateTime
返回自字符串格式为:yyyy-MM-dd HH:mm:ss -
formatDateTimeStr
返回自字符串格式为:yyyyMMddHHmmssSSS -
formatTime
返回自字符串格式为:HH:mm:ss -
formatDate
返回自字符串格式为:yyyy-MM-dd -
formatDateMonth
返回自字符串格式为:yyyy-MM -
formatDateTime
返回自字符串格式为:yyyy-MM-dd HH:mm:ss -
formatDateTimeStr
返回自字符串格式为:yyyyMMddHHmmssSSS -
formatTime
返回自字符串格式为:HH:mm:ss -
datePath
日期路径 即年/月/日 如2018/08/08 -
format
返回自定义格式字符串 -
formatTime
返回自定义格式字符串 -
convertToDate
public static Date convertToDate(java.time.temporal.TemporalAccessor temporalAccessor, java.time.ZoneId zoneId) 将 TemporalAccessor 转换为 Date- Parameters:
temporalAccessor-- Returns:
-
formatTime
将localTime + 时区 转为UTC时间 返回自定义格式字符串 -
parseTime
-
parseTimeSd
- Parameters:
aMask-strDate-- Returns:
-
parseDate
只支持格式yyyy-MM-dd -
parseDateMonth
只支持格式yyyy-MM -
parseDateTime
只支持格式yyyy-MM-dd HH:mm:ss -
parseDateDay
只支持格式yyMMdd -
parseTime
只支持格式HH:mm:ss -
parse
支持自定义格式转换- Throws:
ParseException
-
parse
年4位,月、日、时、分、秒各2位,毫秒3位,支持从右边删除任意部分,如:只有年月日,或者只有年月等- Throws:
ParseException
-
format
毫秒数转为字符串 按照指定格式转换- Parameters:
timestamp-- Returns:
-
getDateStart
获取日期的开始时间- Parameters:
dateStr- 日期Str- Returns:
-
getDateEnd
获取日期的结束时间- Parameters:
dateStr- 日期Str- Returns:
-
getServerStartDate
获取服务器启动时间 -
getDatePoor
计算两个时间差 -
getCurrentTimestamp
public static long getCurrentTimestamp()获取当前时间戳,单位秒- Returns:
-
getCurrentTimestampMs
public static long getCurrentTimestampMs()获取当前时间戳,单位毫秒- Returns:
-
getCurrentDate
-
getTimeInteval
-
addYears
-
addMonths
-
addWeeks
-
addDays
-
addHours
-
addMinutes
-
addSeconds
-
getTodayString
-
nextDate
- Throws:
ParseException
-
getYear
-
getYear
-
appendTime
-
getMorning
获取凌晨00:00:00- Parameters:
date- 任意时间- Returns:
- Date
-
getMorningStr
获取给定日期0点时间的字符串- Parameters:
date- 任意时间- Returns:
- String
-
getNightStr
获取给定日期23.59.59秒的时间字符串- Parameters:
date- 任意时间当天- Returns:
- String
-
getNight
获得 某天的23:59:59- Parameters:
date- 任意时间- Returns:
- Date
-
getWeekOfYear
取得日期是某年的第几周- Parameters:
date- 任意时间- Returns:
- int
-
getDaysBetween
得两个日期之间的相差多少天 -
between
判断两个日期相差的时长
返回 给定单位的时长差- Parameters:
unit- 相差的单位:相差 天DateUnit.DAY、小时DateUnit.HOUR等- Returns:
- 时长差
-
getWeekDay
根据日期取得星期几 weekIndex = 0 表示星期日,依次类推 -
getWeekDayEnum
-
setWeekDay
设置日期到那一周的周几,weekIndex = 0 表示星期日,依次类推 -
firstDayInMonth
public static boolean firstDayInMonth() -
isDayOfMonth
date是否是给定的第x天- Parameters:
date- dateday- day- Returns:
- boolean
-
getMonthBeginStamp
public static long getMonthBeginStamp()获取当月0点毫秒时间- Returns:
- long
-
getMonthEndStamp
public static long getMonthEndStamp()获取当月月底毫秒时间- Returns:
- long
-
getMonthBeginStamp
获取指定时间当月0点毫秒时间- Returns:
- long
-
getMonthBeginDateTime
获取指定时间当月0点毫秒时间- Returns:
- long
-
getLastStampOfMonth
获得某月的最后一天的最后时刻- Parameters:
date- 要获取的月份- Returns:
- long
-
getLastDateTimeOfMonth
获得某月的最后一天的最后时间- Parameters:
date- 要获取的月份- Returns:
- Date
-
thisYear
public static int thisYear()当前年份- Returns:
-
isLeapYear
public static boolean isLeapYear(int year) 是否闰年- Parameters:
year- 年- Returns:
- 是否闰年
-
getQuarterStartTime
当前季度的开始时间- Returns:
- Date
-
getQuarterStartStamp
当前季度的开始时间- Returns:
- long
-
getQuarterEndTime
当前季度的结束时间- Returns:
- Date
-
getQuarterEndStamp
当前季度的结束时间- Returns:
- long
-
quarterTime
获取当前日期所属季度开始结束时间- Parameters:
date- 任意时间- Returns:
-
quarterTime
获取日期所属季度开始结束时间- Returns:
-
getYearStartTime
当前年的开始时间- Returns:
- Date
-
getYearStartStamp
当前年的开始时间- Returns:
- long
-
getYearEndTime
当前年的结束时间- Returns:
- Date
-
getYearEndStamp
当前年的结束时间- Returns:
- long
-
getWeekDayStartTime
获得本周的第一天,周一- Returns:
- Date
-
getWeekDayStartStamp
获得本周的第一天,周一- Returns:
- long
-
getWeekDayEndTime
获得本周的最后一天,周日- Returns:
- Date
-
getWeekDayEndStamp
获得本周的最后一天,周日- Returns:
- long
-
getHalfYearStartTime
获取前/后半年的开始时间- Returns:
- date
-
getHalfYearStartStamp
获取前/后半年的开始时间- Returns:
- date
-
getHalfYearEndTime
获取前/后半年的结束时间- Returns:
- date
-
getHalfYearEndStamp
获取前/后半年的结束时间- Returns:
- date
-
getBetweenWithDay
获取间隔 1 天 的时间列表- Parameters:
startDate- 开始时间endDate- 结束时间- Returns:
- List
-
getBetweenWithWeek
获取间隔 1 周 的时间列表- Parameters:
startDate- 开始时间endDate- 结束时间- Returns:
- List
-
getBetweenWithMonth
获取间隔 1月 (30.44 天) 的时间列表- Parameters:
startDate- 开始时间endDate- 结束时间- Returns:
- List
-
getBetweenWithYear
获取间隔 1年 (365.24 天) 的时间列表- Parameters:
startDate- 开始时间endDate- 结束时间- Returns:
- List
-
dateBetween
获取两个时间直接指定间隔天数列表- Parameters:
startDate- 开始时间endDate- 结束时间interval- 时间间隔- Returns:
- List
-
isOverlap
public static boolean isOverlap(Date leftStartDate, Date leftEndDate, Date rightStartDate, Date rightEndDate) 判断两个时间段是否有重叠- Parameters:
leftStartDate- 区间1开始时间leftEndDate- 区间1结束时间rightStartDate- 区间2开始时间rightEndDate- 区间2结束时间- Returns:
-