类 JtlwDateTimeUtils

java.lang.Object
javabase.lorenwang.tools.common.JtlwDateTimeUtils

public class JtlwDateTimeUtils
extends Object
功能作用:时间工具类 初始注释时间: 2019-01-28 下午 18:30:6 创建人:王亮(Loren) 思路: 方法: 每天的时间毫秒数--DAY_TIME_MILLISECOND 每小时的时间毫秒数--HOUR_TIME_MILLISECOND 获取当前时间的毫秒值--getMillisecond() 获取当前时间的秒值--getSecond() 格式化指定时间到指定格式--getFormatDateTime(pattern,dateTime) 格式化时间--getFormatDateTime(pattern,date) 格式化当前时间到指定格式--getFormatDateNowTime(pattern) 格式化当前时间到指定格式,并返回该格式的相应毫秒值--getFormatNowTimeToMillisecond(pattern) 根据日期时间获得毫秒数--getMillisecond(dateAndTime,dateAndTimeFormat) 根据日期时间获得秒数--getSecond(dateAndTime,dateAndTimeFormat) 根据输入的年份判断该年份是否是闰年,是则返回true--isLeapYear(year) 根据输入的年份判断该年份是否是闰年,是则返回true--isLeapYearForTime(yearTime) 根据月日判断星座--getConstellation(time) 根据日期获取 星期--dateToWeek(time) 获取一个月的所有时间列表--getMonthTimeList(monthTime,firstWeek,onlyMonth) 是否是同一天时间--isOneDay(timeOne, timeTwo) 获取指定时间下个月第一天的时间--getNextMonthStartDayTime(time) 获取指定时间上个月第一天的时间--getLastMonthStartDayTime(time) 获取倒计时天数--getCountdownDay(millisecondTime) 获取倒计时小时,总小时,可能会超过24小时以上--getCountdownHours(millisecondTime) 获取倒计时小时, 如果useOneDay为true的话,那么返回时间不会超过24小时--getCountdownHours(millisecondTime,useOneDay) 获取倒计时分钟,总小时,可能会超过24小时以上--getCountdownMinutes(millisecondTime) 获取倒计时小时, 如果useOnHours为true的话,那么返回时间不会超过60小时--getCountdownMinutes(millisecondTime,useOnHours) 获取倒计时秒,总秒数,可能会超过60s以上--getCountdownMillisecond(millisecondTime) 获取倒计时秒, 如果useOnHours为true的话,那么返回时间不会超过60s以上--getCountdownMillisecond(millisecondTime,useOnMinutes) 获取年份列表--getYearList(leftYearCount,rightYearCount) 获取月份列表--getMonthList(yearTime,asOfCurrent) 获取日期列表--getDayList(monthTime,asOfCurrent) 获取年龄--getAge(birthTime,isReal) 注意: 修改人: 修改时间: 备注:
作者:
王亮(Loren)
  • 字段详细资料

    • DAY_TIME_MILLISECOND

      public static long DAY_TIME_MILLISECOND
      每天的时间毫秒数
    • HOUR_TIME_MILLISECOND

      public static long HOUR_TIME_MILLISECOND
      每小时的时间毫秒数
    • YEAR_PATTERN

      public static String YEAR_PATTERN
      年份默认格式
    • MONTH_PATTERN

      public static String MONTH_PATTERN
      月份默认格式
    • DAY_PATTERN

      public static String DAY_PATTERN
      日期默认格式
  • 方法详细资料

    • getInstance

      public static JtlwDateTimeUtils getInstance()
    • getMillisecond

      public Long getMillisecond()
      获取当前时间的毫秒值
      返回:
      毫秒数
    • getSecond

      public Long getSecond()
      获取当前时间的秒值
      返回:
      秒值
    • getFormatDateTime

      public String getFormatDateTime​(String pattern, long dateTime)
      格式化指定时间到指定格式

      yyyy.MM.dd G 'at' hh:mm:ss z 如 '2002-1-1 AD at 22:10:59 PSD' yy/MM/dd HH:mm:ss 如 '2002/1/1 17:55:00' yy/MM/dd HH:mm:ss pm 如 '2002/1/1 17:55:00 pm' yy-MM-dd HH:mm:ss 如 '2002-1-1 17:55:00' yy-MM-dd HH:mm:ss am 如 '2002-1-1 17:55:00 am'

      参数:
      pattern - 时间格式正则
      dateTime - 时间戳
      返回:
      转换后字符串
    • getFormatDateTime

      public String getFormatDateTime​(String pattern, Date date)
      格式化时间
      参数:
      pattern - 格式
      date - 时间
      返回:
      成功返回时间字符串,否则返回null
    • getFormatDateNowTime

      public String getFormatDateNowTime​(String pattern)
      格式化当前时间到指定格式
      参数:
      pattern - 时间格式正则
      返回:
      转换后字符串
    • getFormatNowTimeToMillisecond

      public Long getFormatNowTimeToMillisecond​(String pattern)
      格式化当前时间到指定格式,并返回该格式的相应毫秒值
      参数:
      pattern - 时间格式正则
      返回:
      转换后字符串
    • getMillisecond

      public long getMillisecond​(String dateAndTime, String dateAndTimeFormat)
      根据日期时间获得毫秒数
      参数:
      dateAndTime - 日期时间:"201104141302"
      dateAndTimeFormat - 日期时间的格式:"yyyy MM dd hh mm"
      返回:
      返回毫秒数
    • getSecond

      public long getSecond​(String dateAndTime, String dateAndTimeFormat)
      根据日期时间获得秒数
      参数:
      dateAndTime - 日期时间:"201104141302"
      dateAndTimeFormat - 日期时间的格式:"yyyy MM dd hh mm"
      返回:
      返回秒数
    • isLeapYear

      public boolean isLeapYear​(Integer year)
      根据输入的年份判断该年份是否是闰年,是则返回true
      参数:
      year - 要输入的年份
      返回:
      是闰年返回true,否则返回false
    • isLeapYearForTime

      public boolean isLeapYearForTime​(long yearTime)
      根据输入的年份判断该年份是否是闰年,是则返回true
      参数:
      yearTime - 要输入的年份
      返回:
      是闰年返回true,否则返回false
    • dateToWeek

      public int dateToWeek​(long time)
      根据日期获取 星期
      参数:
      time - 时间
      返回:
      从星期日开始的下标
    • getMonthTimeList

      public List<Long> getMonthTimeList​(long monthTime, int firstWeek, boolean onlyMonth)
      获取一个月的所有时间列表
      参数:
      monthTime - 月份时间
      firstWeek - 开始的星期,也就是星期几开始,0代表星期日,1代表星期一,依次类推
      onlyMonth - 是否只有当月的
      返回:
      月度列表,如果不返回当月的则非当月的位置元素会为空
    • isOneDay

      public boolean isOneDay​(long timeOne, long timeTwo)
      是否是同一天时间
      参数:
      timeOne - 时间1
      timeTwo - 时间2
      返回:
      是同一天返回true
    • getNextMonthStartDayTime

      public long getNextMonthStartDayTime​(long time)
      获取指定时间下个月第一天的时间
      参数:
      time - 指定时间
      返回:
      下个月1号的时间
    • getLastMonthStartDayTime

      public long getLastMonthStartDayTime​(long time)
      获取指定时间上个月第一天的时间
      参数:
      time - 指定时间
      返回:
      上个月1号的时间
    • getCountdownDay

      public int getCountdownDay​(long millisecondTime)
      获取倒计时天数
      参数:
      millisecondTime - 时间毫秒数
      返回:
      倒计时天数
    • getCountdownHours

      public int getCountdownHours​(long millisecondTime)
      获取倒计时小时,总小时,可能会超过24小时以上
      参数:
      millisecondTime - 时间毫秒数
      返回:
      倒计时小时,总小时,可能会超过24小时以上
    • getCountdownHours

      public int getCountdownHours​(long millisecondTime, boolean useOneDay)
      获取倒计时小时, 如果useOneDay为true的话,那么返回时间不会超过24小时
      参数:
      millisecondTime - 时间毫秒数
      useOneDay - 是否使用一天做处理
      返回:
      倒计时小时, 如果useOneDay为true的话,那么返回时间不会超过24小时
    • getCountdownMinutes

      public int getCountdownMinutes​(long millisecondTime)
      获取倒计时分钟,总小时,可能会超过24小时以上
      参数:
      millisecondTime - 时间毫秒数
      返回:
      倒计时分钟,总分钟,可能会超过60分钟以上
    • getCountdownMinutes

      public int getCountdownMinutes​(long millisecondTime, boolean useOnHours)
      获取倒计时小时, 如果useOnHours为true的话,那么返回时间不会超过60小时
      参数:
      millisecondTime - 时间毫秒数
      useOnHours - 是否使用一天做处理
      返回:
      倒计时小时, 如果useOnHours为true的话,那么返回时间不会超过60分钟以上
    • getCountdownMillisecond

      public int getCountdownMillisecond​(long millisecondTime)
      获取倒计时秒,总秒数,可能会超过60s以上
      参数:
      millisecondTime - 时间毫秒数
      返回:
      倒计时秒,总秒数,可能会超过60s以上
    • getCountdownMillisecond

      public int getCountdownMillisecond​(long millisecondTime, boolean useOnMinutes)
      获取倒计时秒, 如果useOnHours为true的话,那么返回时间不会超过60s以上
      参数:
      millisecondTime - 时间毫秒数
      useOnMinutes - 是否使用一分钟做处理
      返回:
      倒计时倒计时秒, 如果useOnHours为true的话,那么返回时间不会超过60s以上
    • getYearList

      public List<Long> getYearList​(int leftYearCount, int rightYearCount)
      获取年份列表
      参数:
      leftYearCount - 左侧年份需要补充的数量,不包含当当年
      rightYearCount - 右侧年份需要补充的数量,不包含当年
      返回:
      年份列表
    • getMonthList

      public List<Long> getMonthList​(long yearTime, boolean asOfCurrent)
      获取月份列表
      参数:
      yearTime - 年份时间
      asOfCurrent - 是否截止到当前
      返回:
      月份列表
    • getDayList

      public List<Long> getDayList​(long monthTime, boolean asOfCurrent)
      获取日期列表
      参数:
      monthTime - 年份时间
      asOfCurrent - 是否截止到当前
      返回:
      日期列表
    • getConstellation

      public int getConstellation​(long time)
      根据时间获取星座
      参数:
      time - 时间
      返回:
      星座顺序下标
    • getAge

      public int getAge​(long birthTime, boolean isReal)
      获取年龄
      参数:
      birthTime - 出生日期
      isReal - 是否获取实岁,true获取实岁,false获取虚岁
      返回:
      年龄整数