Class Time

java.lang.Object
com.imyeyu.utils.Time

public class Time extends Object
时间转换相关
Version:
2021-06-10 20:07
Author:
夜雨
  • Field Details

  • Constructor Details

    • Time

      public Time()
  • Method Details

    • between

      public static Time.Between between(long begin, long end)
      计算两个时间戳精确的日期时间差
      Parameters:
      begin - 开始时间戳
      end - 结束时间戳
      Returns:
      时差
    • now

      public static long now()
      获取此刻毫秒
      Returns:
      毫秒
    • nowString

      public static String nowString()
      获取当前时间 yyyy-MM-dd HH:mm:ss
      Returns:
      当前时间
    • yesterday

      public static long yesterday()
      获取昨天零时时间戳
      Returns:
      昨天零时时间戳
    • today

      public static long today()
      获取今天零时时间戳
      Returns:
      今天零时时间戳
    • tomorrow

      public static long tomorrow()
      获取明天零时时间戳
      Returns:
      明天零时时间戳
    • toDate

      public static String toDate(long unixTime)
      转义为日期 yyyy-MM-dd
      Parameters:
      unixTime - 时间戳
      Returns:
      日期字符串
    • toTime

      public static String toTime(long unixTime)
      转义为时间 HH:mm:ss
      Parameters:
      unixTime - 时间戳
      Returns:
      时间字符串
    • toDateTime

      public static String toDateTime(long unixTime)
      转义为日期时间 yyyy-MM-dd HH:mm:ss
      Parameters:
      unixTime - 时间戳
      Returns:
      日期时间字符串
    • toDateTime

      public static String toDateTime(Date date)
      转义为日期时间 yyyy-MM-dd HH:mm:ss
      Parameters:
      date - 时间对象
      Returns:
      日期时间字符串
    • fromLocalDate

      public static Long fromLocalDate(LocalDate date)
      本地时间对象转时间戳(本地时区)
      Parameters:
      date - 本地日期对象
      Returns:
      时间戳
    • fromLocalDateTime

      public static Long fromLocalDateTime(LocalDateTime dateTime)
      本地时间对象转时间戳(本地时区)
      Parameters:
      dateTime - 本地日期对象
      Returns:
      时间戳
    • toLocalDateTime

      public static LocalDateTime toLocalDateTime(Long unixTime)
      时间戳转本地日期(本地时区)
      Parameters:
      unixTime - 时间戳
      Returns:
      本地日期对象
    • parseToMS

      public static long parseToMS(String timeStr)
      将时间字符串解析为毫秒值

      支持的格式示例:

       10               = 10
       10ms             = 10
       10s              = 10,000
       10m              = 600,000
       10h              = 36,000,000
       10d = 10D = 10 d = 864,000,000
       10.5d            = 907,200,000
       
      Parameters:
      timeStr - 时间字符串
      Returns:
      毫秒
      Throws:
      IllegalArgumentException - 输入格式无效