Package org.qiunet.utils.date
Class DateUtil
java.lang.Object
org.qiunet.utils.date.DateUtil
时间date相关的工具类
也可以使用DateTimeFormatter 但是使用线程变量已经可以解决问题. 就不再修改.
- Author:
- qiunet
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final long一天的毫秒数static final long一天的秒static final String默认日期格式static final String默认的时间格式(日期 时间)static final DateTimeFormatter外面直接使用 LocalDateTime.format() 可以搞定static final long一周的毫秒数static final long一周的毫秒数 -
Method Summary
Modifier and TypeMethodDescriptionstatic longcalConsumeMillisSeconds(IRunnable runnable) 计算Runnable 消耗毫秒static Instant得到当前的 Instantstatic longstatic long当前的秒static StringdateToString(long millis) 日期转字符串 默认格式static StringdateToString(long millis, String format) 日期转字符串 指定格式static StringdateToString(LocalDateTime date) 格式化为 yyyy-MM-dd HH:mm:ssstatic StringdateToString(LocalDateTime date, String format) 日期转时间static StringdateToString(Date date) 日期转字符串 指定格式static StringdateToString(Date date, String format) 日期转字符串 指定格式static intstatic intgetDayOfMonth(long time) static int获取系统当前的星期 1-7static intgetDayOfWeek(long time) 获取系统当前的星期 1-7static int获取系统当前的天 1 to 365, or 366static intgetDayOfYear(long time) 获取传入毫秒的天 1 to 365, or 366static ZoneId获得默认区 IDstatic intgetLastDayOfMonth(int year, int month) 获得最后天数static LocalDateTimegetLocalDateTime(long milliseconds) 根据时间戳 得到LocalDateTimestatic LocalDateTimegetLocalDateTime(long milliseconds, ZoneOffset zoneOffset) 根据时间戳 得到LocalDateTimestatic longgetMilliByTime(LocalDateTime time) 获取指定日期的毫秒static longgetMilliByTime(LocalDateTime time, ZoneOffset offset) 获取指定日期的毫秒static long获取指定日期的秒static booleanisBetweenDays(LocalDateTime date, LocalDateTime dateBefore, LocalDateTime dateLast) 是否介于两个日期之间static booleanisLeap(int year) 是否是闰年static booleanisSameDay(long time1, long time2) static booleanisSameDay(LocalDateTime time1, LocalDateTime time2) static booleanisSameMonth(long time1, long time2) static booleanisSameQuarter(long time1, long time2) static booleanisSameWeek(long time1, long time2) 判断两个时间是否在同一周(注意这里周日和周一判断是在一周里的)static booleanisSameYear(long time1, long time2) static LocalDateTime当前时间static LocalDateTimenowLocalDateTime(ZoneId zoneId) 当前时间static DateTimeFormatterreturnFormatter(String pattern) 使用LocalDateTime格式化时间.static voidsetTimeOffset(long offsetValue, TimeUnit unit) 对全局时间偏移做调整static LocalDateTimestringToDate(String stringValue) 字符串转日期 按默认格式static LocalDateTimestringToDate(String stringValue, String format) 字符串转日期 按指定格式
-
Field Details
-
DEFAULT_DATE_TIME_FORMAT
默认的时间格式(日期 时间)- See Also:
-
DEFAULT_DATE_FORMAT
默认日期格式- See Also:
-
DEFAULT_DATE_TIME_FORMATTER
外面直接使用 LocalDateTime.format() 可以搞定 -
DAY_SECONDS
public static final long DAY_SECONDS一天的秒- See Also:
-
DAY_MS
public static final long DAY_MS一天的毫秒数- See Also:
-
WEEK_SECONDS
public static final long WEEK_SECONDS一周的毫秒数- See Also:
-
WEEK_MS
public static final long WEEK_MS一周的毫秒数- See Also:
-
-
Method Details
-
currSeconds
public static long currSeconds()当前的秒- Returns:
-
currentInstant
得到当前的 Instant- Returns:
-
nowLocalDateTime
当前时间- Returns:
-
nowLocalDateTime
当前时间- Parameters:
zoneId-- Returns:
-
getDefaultZoneId
获得默认区 ID- Returns:
-
setTimeOffset
对全局时间偏移做调整- Parameters:
offsetValue-
-
calConsumeMillisSeconds
计算Runnable 消耗毫秒- Parameters:
runnable- 执行代码- Returns:
- 毫秒
- Throws:
Exception
-
dateToString
日期转字符串 默认格式- Parameters:
millis-- Returns:
-
dateToString
格式化为 yyyy-MM-dd HH:mm:ss- Parameters:
date-- Returns:
-
getMilliByTime
获取指定日期的毫秒- Parameters:
time-- Returns:
-
getMilliByTime
获取指定日期的毫秒- Parameters:
time-- Returns:
-
getSecondsByTime
获取指定日期的秒- Parameters:
time-- Returns:
-
getLocalDateTime
根据时间戳 得到LocalDateTime- Parameters:
milliseconds-- Returns:
-
getLocalDateTime
根据时间戳 得到LocalDateTime- Parameters:
milliseconds-zoneOffset-- Returns:
-
dateToString
日期转字符串 指定格式- Parameters:
date-- Returns:
-
dateToString
日期转字符串 指定格式- Parameters:
date-format-- Returns:
-
dateToString
日期转字符串 指定格式- Parameters:
millis-format-- Returns:
-
dateToString
日期转时间- Parameters:
date-format-- Returns:
-
stringToDate
字符串转日期 按指定格式- Parameters:
stringValue-format-- Returns:
-
stringToDate
字符串转日期 按默认格式- Parameters:
stringValue-- Returns:
-
isBetweenDays
public static boolean isBetweenDays(LocalDateTime date, LocalDateTime dateBefore, LocalDateTime dateLast) 是否介于两个日期之间- Parameters:
date-dateBefore-dateLast-- Returns:
-
currentTimeMillis
public static long currentTimeMillis()- Returns:
- 获取当前纪元毫秒 1970-01-01T00:00:00Z.
-
isSameDay
- Parameters:
time1-time2-- Returns:
-
isSameDay
public static boolean isSameDay(long time1, long time2) - Parameters:
time1-time2-- Returns:
-
isSameWeek
public static boolean isSameWeek(long time1, long time2) 判断两个时间是否在同一周(注意这里周日和周一判断是在一周里的)- Parameters:
time1-time2-- Returns:
-
isSameMonth
public static boolean isSameMonth(long time1, long time2) - Parameters:
time1-time2-- Returns:
-
isSameQuarter
public static boolean isSameQuarter(long time1, long time2) - Parameters:
time1-time2-- Returns:
-
isSameYear
public static boolean isSameYear(long time1, long time2) - Parameters:
time1-time2-- Returns:
-
getDayOfMonth
public static int getDayOfMonth(long time) - Parameters:
time-- Returns:
-
getDayOfMonth
public static int getDayOfMonth()- Returns:
-
getDayOfYear
public static int getDayOfYear(long time) 获取传入毫秒的天 1 to 365, or 366- Parameters:
time-- Returns:
-
getDayOfYear
public static int getDayOfYear()获取系统当前的天 1 to 365, or 366- Returns:
-
getDayOfWeek
public static int getDayOfWeek(long time) 获取系统当前的星期 1-7- Returns:
-
getDayOfWeek
public static int getDayOfWeek()获取系统当前的星期 1-7- Returns:
-
returnFormatter
使用LocalDateTime格式化时间. 取到对应的 DateTimeFormatter- Parameters:
pattern-- Returns:
-
isLeap
public static boolean isLeap(int year) 是否是闰年- Parameters:
year-- Returns:
-
getLastDayOfMonth
public static int getLastDayOfMonth(int year, int month) 获得最后天数- Parameters:
month-year-- Returns:
-