类 DateUtil

java.lang.Object
com.weicoder.common.util.DateUtil
直接已知子类:
U.D

public sealed class DateUtil extends Object permits U.D
获得日期,日期类型和字符串类型之间的转化
作者:
WD
  • 构造器概要

    构造器
    构造器
    说明
     
  • 方法概要

    修饰符和类型
    方法
    说明
    static long
    diff(long time)
    根据传进来的时间算出与现在时间的差值
    static long
    调用差异时间 按线程保存调用时间每次调用返回上次调用与本次相差时间
    static String
    format(String src, String srcfmt, String desfmt)
    日期字符串格式转换
    static Date
    取得当前时间 返回的是Date类型
    static String
    取得格式为默认格式的系统日期 返回的日期是字符串格式
    static String
    getDate(int number)
    取得当前日期的N天后的日期(如果想获得前几天的日期用-number) 默认格式
    static String
    getDate(int time, int number)
    取得当前日期的N天后的日期(如果想获得前几天的日期用-number) 默认格式
    static String
    getDate(int time, int number, String format)
    取得当前日期的N天后的日期(如果想获得前几天的日期用-number)
    static String
    getDate(int number, String format)
    取得当前日期的N天后的日期(如果想获得前几天的日期用-number)
    static String
    getDate(String format)
    取得指定格式的系统日期 返回的日期是字符串格式
    static String
    getDate(String date, int number)
    取得当前日期的N天后的日期(如果想获得前几天的日期用-number)
    static String
    getDate(String date, int number, String format)
    取得当前日期的N天后的日期(如果想获得前几天的日期用-number)
    static String
    getDate(Date date, int number)
    取得当前日期的N天后的日期(如果想获得前几天的日期用-number)
    static String
    getDate(Date date, int number, String format)
    取得当前日期的N天后的日期(如果想获得前几天的日期用-number)
    static int
    获取当前月份的 日
    static int
    getDay(Date date)
    取指定日期月份的日
    static int
    根据日期取得星期几 周日返回的是0
    static int
    根据日期取得星期几 默认格式 周日返回的是0
    static int
    getDayOfMonth(String date, String format)
    根据日期取得星期几 周日返回的是0
    static int
    根据日期取得星期几 周日返回的是0
    static String[]
    根据日期取得当前自然星期7天日期
    static int
    根据日期取得星期几 周日返回的是0
    static int
    根据日期取得星期几 默认格式 周日返回的是0
    static int
    getDayOfWeek(String date, String format)
    根据日期取得星期几 周日返回的是0
    static int
    根据日期取得星期几 周日返回的是0
    static String[]
    根据本周的的日期
    static String[]
    根据日期取得当前星期7天的日期 默认格式
    static String[]
    getDayOfWeeks(String date, String format)
    根据日期取得当前星期7天的日期 默认格式
    static String[]
    根据日期取得当前星期7天日期
    static String[]
    getDayOfWeeks(Date date, String format)
    根据日期取得当前星期7天日期
    static int
    根据日期取得一年的第N天
    static int
    根据日期取得一年的第N天
    static int
    getDayOfYear(String date, String format)
    根据日期取得一年的第N天
    static int
    根据日期取得一年的第N天
    static String
    根据给定的日期字符串返回它的日期Format
    static int
    获取当前 时
    static int
    getHour(Date date)
    获取当前 时
    static String
    取得格式为yyyy-MM-dd HH:mm:ss 的系统日期 返回的日期是字符串格式
    static int
    获取当前 分
    static int
    获取当前 分
    static int
    获取当前 月
    static String
    getMonth(int number)
    取得当前日期的N月后的日期(如果想获得前几月的日期用-number) 默认格式
    static String
    getMonth(int number, String format)
    取得当前日期的N月后的日期(如果想获得前几月的日期用-number)
    static String
    getMonth(String date, int number)
    取得当前日期的N月后的日期(如果想获得前几月的日期用-number)
    static String
    getMonth(String date, int number, String format)
    取得当前日期的N月后的日期(如果想获得前几月的日期用-number)
    static int
    getMonth(Date date)
    取指定日期的月份
    static String
    getMonth(Date date, int number)
    取得当前日期的N月后的日期(如果想获得前几月的日期用-number)
    static String
    getMonth(Date date, int number, String format)
    取得当前日期的N月后的日期(如果想获得前几月的日期用-number)
    static int
    获得当前月份有几天
    static int
    getMonthHaveDay(int month)
    获得增加指定月份有几天
    static int
    获得指定月份有几天
    static String[]
    获得当前日期的月份所有日期
    static String[]
    根据指定日期的月份所有日期
    static String[]
    getMonths(String date, String format)
    根据指定日期的月份所有日期
    static String[]
    根据指定日期的月份所有日期
    static String[]
    getMonths(Date date, String format)
    根据指定日期的月份所有日期
    static int
    获取当前 秒
    static int
    获取当前 秒
    static String
    取得格式为yyyy-MM-dd 的系统日期 返回的日期是字符串格式
    static String
    取得格式为HH:mm:ss 的系统日期 返回的日期是字符串格式
    static int
    取得当前时间的秒数 返回的是int类型
    static int
    getTime(int time, int number)
    取得当前日期的N天后的日期(如果想获得前几天的日期用-number) 默认格式
    static int
    getTime(int time, int number, String format)
    取得当前日期的N天后的日期(如果想获得前几天的日期用-number)
    static int
    获得现在时间毫秒数
    static int
    getTime(String date, String format)
    获得现在时间毫秒数
    static int
    getTime(Date date)
    获得现在时间毫秒数
    static String
    取得格式为yyyyMMdd 的系统日期 返回的日期是字符串格式
    static int
    根据日期取得一年的第N周
    static int
    根据日期取得一年的第N周 默认格式
    static int
    getWeek(String date, String format)
    根据日期取得一年的第N周
    static int
    getWeek(Date date)
    根据日期取得一年的第N周
    static int
    获取当前 年
    static int
    getYear(int number)
    取得当前日期的N年后的日期(如果想获得前几年的日期用-number) 默认格式
    static int
    getYear(String date, int number)
    取得当前日期的N年后的日期(如果想获得前几年的日期用-number)
    static int
    getYear(String date, int number, String format)
    取得当前日期的N年后的日期(如果想获得前几年的日期用-number)
    static int
    getYear(Date date)
    取指定日期的年份
    static int
    getYear(Date date, int number)
    取得当前日期的N年后的日期(如果想获得前几年的日期用-number)
    static int
    获得当前年份有几天
    static int
    获得指定年份有几天
    static int
    marginDay(String oneDate, String twoDate)
    计算两个日期相差的天数 传入的日期格式是 默认格式
    static int
    marginDay(String oneDate, String twoDate, String format)
    计算两个日期相差的天数
    static int
    marginDay(Date oneDate, Date twoDate)
    计算两个日期相差的天数
    static int
    marginMonth(String oneDate, String twoDate)
    两个日期相隔几个月 默认日期格式
    static int
    marginMonth(String oneDate, String twoDate, String format)
    两个日期相隔几个月
    static int
    marginMonth(Date oneDate, Date twoDate)
    两个日期相隔几个月
    static long
    now()
    获得当前时间 毫秒 System.currentTimeMillis()
    static String
    secondToTime(int time)
    转换时间到字符串格式 例如 输入300 转成00:05:00
    static int
    获得当前时间 秒 System.currentTimeMillis()/1000
    static Date
    toDate(String dateString)
    字符串转换为日期 默认格式
    static Date
    toDate(String dateString, String format)
    字符串转换为日期 dateString为空或异常返回当前时间
    static String
    toString(int time)
    取得time的日期
    static String
    toString(int time, String format)
    取得time的日期
    static String
    toString(long time)
    取得time的日期
    static String
    toString(long time, String format)
    取得time的日期
    static String
    toString(Date date)
    根据给定的时间返回相对的字符串 默认格式
    static String
    toString(Date date, String format)
    根据时间变量返回时间字符串

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 构造器详细资料

    • DateUtil

      public DateUtil()
  • 方法详细资料

    • getFormat

      public static String getFormat(String date)
      根据给定的日期字符串返回它的日期Format
      参数:
      date - 日期
      返回:
      Format
    • getDate

      public static String getDate()
      取得格式为默认格式的系统日期 返回的日期是字符串格式
      返回:
      String 当前日期
    • getLongDate

      public static String getLongDate()
      取得格式为yyyy-MM-dd HH:mm:ss 的系统日期 返回的日期是字符串格式
      返回:
      String 当前日期
    • getShortDate

      public static String getShortDate()
      取得格式为yyyy-MM-dd 的系统日期 返回的日期是字符串格式
      返回:
      String 当前日期
    • getTinyDate

      public static String getTinyDate()
      取得格式为yyyyMMdd 的系统日期 返回的日期是字符串格式
      返回:
      String 当前日期
    • getTheDate

      public static String getTheDate()
      取得格式为HH:mm:ss 的系统日期 返回的日期是字符串格式
      返回:
      String 当前日期
    • getDate

      public static String getDate(String format)
      取得指定格式的系统日期 返回的日期是字符串格式
      参数:
      format - 日期格式,如 "yyyy-MM-dd HH:mm:sss"
      返回:
      String 当前日期
    • getCurrentDate

      public static Date getCurrentDate()
      取得当前时间 返回的是Date类型
      返回:
      Date 当前日期
    • getTime

      public static int getTime()
      取得当前时间的秒数 返回的是int类型
      返回:
      int
    • getTime

      public static int getTime(Date date)
      获得现在时间毫秒数
      参数:
      date - 要取的时间
      返回:
      int
    • getTime

      public static int getTime(String date)
      获得现在时间毫秒数
      参数:
      date - 要取的时间
      返回:
      int
    • getTime

      public static int getTime(String date, String format)
      获得现在时间毫秒数
      参数:
      date - 要取的时间
      format - 时间字符串样式
      返回:
      int
    • getTime

      public static int getTime(int time, int number)
      取得当前日期的N天后的日期(如果想获得前几天的日期用-number) 默认格式
      参数:
      time - 时间
      number - N天
      返回:
      N天的日期
    • getTime

      public static int getTime(int time, int number, String format)
      取得当前日期的N天后的日期(如果想获得前几天的日期用-number)
      参数:
      time - 时间
      number - N天
      format - 日期格式
      返回:
      N天的日期
    • toString

      public static String toString(Date date, String format)
      根据时间变量返回时间字符串
      参数:
      date - 时间变量
      format - 时间字符串样式
      返回:
      返回时间字符串
    • toString

      public static String toString(Date date)
      根据给定的时间返回相对的字符串 默认格式
      参数:
      date - 日期
      返回:
      String 转换后的日期
    • toString

      public static String toString(long time)
      取得time的日期
      参数:
      time - 毫秒
      返回:
      String time的日期
    • toString

      public static String toString(long time, String format)
      取得time的日期
      参数:
      time - 毫秒
      format - 日期显示格式
      返回:
      String time的日期
    • toString

      public static String toString(int time)
      取得time的日期
      参数:
      time - 毫秒
      返回:
      String time的日期
    • toString

      public static String toString(int time, String format)
      取得time的日期
      参数:
      time - 毫秒
      format - 日期显示格式
      返回:
      String time的日期
    • toDate

      public static Date toDate(String dateString)
      字符串转换为日期 默认格式
      参数:
      dateString - 字符串
      返回:
      Date 转换后的日期
    • toDate

      public static Date toDate(String dateString, String format)
      字符串转换为日期 dateString为空或异常返回当前时间
      参数:
      dateString - 字符串
      format - 日期格式
      返回:
      Date 转换后的日期
    • marginDay

      public static int marginDay(String oneDate, String twoDate)
      计算两个日期相差的天数 传入的日期格式是 默认格式
      参数:
      oneDate - 开始日期
      twoDate - 结束日期
      返回:
      返回两个日期相差的天数
    • marginDay

      public static int marginDay(String oneDate, String twoDate, String format)
      计算两个日期相差的天数
      参数:
      oneDate - 开始日期
      twoDate - 结束日期
      format - 日期格式
      返回:
      返回两个日期相差的天数
    • marginDay

      public static int marginDay(Date oneDate, Date twoDate)
      计算两个日期相差的天数
      参数:
      oneDate - 日期
      twoDate - 日期
      返回:
      返回两个日期相差的天数
    • marginMonth

      public static int marginMonth(String oneDate, String twoDate)
      两个日期相隔几个月 默认日期格式
      参数:
      oneDate - 日期
      twoDate - 日期
      返回:
      返回两个日期相隔几个月
    • marginMonth

      public static int marginMonth(String oneDate, String twoDate, String format)
      两个日期相隔几个月
      参数:
      oneDate - 日期
      twoDate - 日期
      format - 日期格式
      返回:
      返回两个日期相隔几个月
    • marginMonth

      public static int marginMonth(Date oneDate, Date twoDate)
      两个日期相隔几个月
      参数:
      oneDate - 日期
      twoDate - 日期
      返回:
      返回两个日期相隔几个月
    • getDayOfWeek

      public static int getDayOfWeek()
      根据日期取得星期几 周日返回的是0
      返回:
      返回星期几
    • getDayOfWeek

      public static int getDayOfWeek(String date)
      根据日期取得星期几 默认格式 周日返回的是0
      参数:
      date - 日期字符串
      返回:
      返回星期几
    • getDayOfWeek

      public static int getDayOfWeek(String date, String format)
      根据日期取得星期几 周日返回的是0
      参数:
      date - 日期字符串
      format - 日期格式
      返回:
      返回星期几
    • getDayOfWeek

      public static int getDayOfWeek(Date date)
      根据日期取得星期几 周日返回的是0
      参数:
      date - 日期
      返回:
      返回星期几
    • getDayOfMonth

      public static int getDayOfMonth()
      根据日期取得星期几 周日返回的是0
      返回:
      返回星期几
    • getDayOfMonth

      public static int getDayOfMonth(String date)
      根据日期取得星期几 默认格式 周日返回的是0
      参数:
      date - 日期字符串
      返回:
      返回星期几
    • getDayOfMonth

      public static int getDayOfMonth(String date, String format)
      根据日期取得星期几 周日返回的是0
      参数:
      date - 日期字符串
      format - 日期格式
      返回:
      返回星期几
    • getDayOfMonth

      public static int getDayOfMonth(Date date)
      根据日期取得星期几 周日返回的是0
      参数:
      date - 日期
      返回:
      返回星期几
    • getDayOfWeeks

      public static String[] getDayOfWeeks()
      根据本周的的日期
      返回:
      本周的日期
    • getDayOfWeeks

      public static String[] getDayOfWeeks(String date)
      根据日期取得当前星期7天的日期 默认格式
      参数:
      date - 日期字符串
      返回:
      本周的日期
    • getDayOfWeeks

      public static String[] getDayOfWeeks(String date, String format)
      根据日期取得当前星期7天的日期 默认格式
      参数:
      date - 日期字符串
      format - 日期格式
      返回:
      本周的日期
    • getDayOfWeeks

      public static String[] getDayOfWeeks(Date date)
      根据日期取得当前星期7天日期
      参数:
      date - 日期
      返回:
      本周的日期
    • getDayOfWeeks

      public static String[] getDayOfWeeks(Date date, String format)
      根据日期取得当前星期7天日期
      参数:
      date - 日期
      format - 返回的日期格式
      返回:
      本周的日期
    • getDayOfNaturalWeeks

      public static String[] getDayOfNaturalWeeks(String date)
      根据日期取得当前自然星期7天日期
      参数:
      date - 日期
      返回:
      本周的日期
    • getWeek

      public static int getWeek()
      根据日期取得一年的第N周
      返回:
      返回第N周
    • getWeek

      public static int getWeek(String date)
      根据日期取得一年的第N周 默认格式
      参数:
      date - 日期字符串
      返回:
      返回第N周
    • getWeek

      public static int getWeek(String date, String format)
      根据日期取得一年的第N周
      参数:
      date - 日期字符串
      format - 日期格式
      返回:
      返回第N周
    • getWeek

      public static int getWeek(Date date)
      根据日期取得一年的第N周
      参数:
      date - 日期
      返回:
      返回第N周
    • getDayOfYear

      public static int getDayOfYear()
      根据日期取得一年的第N天
      返回:
      返回第N天
    • getDayOfYear

      public static int getDayOfYear(String date)
      根据日期取得一年的第N天
      参数:
      date - 日期字符串
      返回:
      返回第N天
    • getDayOfYear

      public static int getDayOfYear(String date, String format)
      根据日期取得一年的第N天
      参数:
      date - 日期字符串
      format - 日期格式
      返回:
      返回第N天
    • getDayOfYear

      public static int getDayOfYear(Date date)
      根据日期取得一年的第N天
      参数:
      date - 日期
      返回:
      返回第N天
    • getDate

      public static String getDate(int number)
      取得当前日期的N天后的日期(如果想获得前几天的日期用-number) 默认格式
      参数:
      number - N天
      返回:
      N天的日期
    • getDate

      public static String getDate(int number, String format)
      取得当前日期的N天后的日期(如果想获得前几天的日期用-number)
      参数:
      number - N天
      format - 日期格式
      返回:
      N天的日期
    • getDate

      public static String getDate(int time, int number)
      取得当前日期的N天后的日期(如果想获得前几天的日期用-number) 默认格式
      参数:
      time - 时间
      number - N天
      返回:
      N天的日期
    • getDate

      public static String getDate(int time, int number, String format)
      取得当前日期的N天后的日期(如果想获得前几天的日期用-number)
      参数:
      time - 时间
      number - N天
      format - 日期格式
      返回:
      N天的日期
    • getDate

      public static String getDate(String date, int number)
      取得当前日期的N天后的日期(如果想获得前几天的日期用-number)
      参数:
      date - 日期字符串
      number - N天
      返回:
      N天的日期
    • getDate

      public static String getDate(String date, int number, String format)
      取得当前日期的N天后的日期(如果想获得前几天的日期用-number)
      参数:
      date - 日期字符串
      number - N天
      format - 日期格式
      返回:
      N天的日期
    • getDate

      public static String getDate(Date date, int number)
      取得当前日期的N天后的日期(如果想获得前几天的日期用-number)
      参数:
      date - 日期
      number - N天
      返回:
      N天的日期
    • getDate

      public static String getDate(Date date, int number, String format)
      取得当前日期的N天后的日期(如果想获得前几天的日期用-number)
      参数:
      date - 日期
      number - N天
      format - 日期格式
      返回:
      N天的日期
    • getMonth

      public static String getMonth(int number)
      取得当前日期的N月后的日期(如果想获得前几月的日期用-number) 默认格式
      参数:
      number - N月
      返回:
      N月的日期
    • getMonth

      public static String getMonth(int number, String format)
      取得当前日期的N月后的日期(如果想获得前几月的日期用-number)
      参数:
      number - N月
      format - 日期格式
      返回:
      N月的日期
    • getMonth

      public static String getMonth(String date, int number)
      取得当前日期的N月后的日期(如果想获得前几月的日期用-number)
      参数:
      date - 日期字符串
      number - N月
      返回:
      N月的日期
    • getMonth

      public static String getMonth(String date, int number, String format)
      取得当前日期的N月后的日期(如果想获得前几月的日期用-number)
      参数:
      date - 日期字符串
      number - N天
      format - 日期格式
      返回:
      N天的日期
    • getMonth

      public static String getMonth(Date date, int number)
      取得当前日期的N月后的日期(如果想获得前几月的日期用-number)
      参数:
      date - 日期
      number - N月
      返回:
      N月的日期
    • getMonth

      public static String getMonth(Date date, int number, String format)
      取得当前日期的N月后的日期(如果想获得前几月的日期用-number)
      参数:
      date - 日期
      number - N月
      format - 日期格式
      返回:
      N月的日期
    • getMonths

      public static String[] getMonths()
      获得当前日期的月份所有日期
      返回:
      返回本月的所有日期
    • getMonths

      public static String[] getMonths(String date)
      根据指定日期的月份所有日期
      参数:
      date - 日期字符串
      返回:
      返回本月的所有日期
    • getMonths

      public static String[] getMonths(String date, String format)
      根据指定日期的月份所有日期
      参数:
      date - 日期字符串
      format - 日期格式
      返回:
      返回本月的所有日期
    • getMonths

      public static String[] getMonths(Date date)
      根据指定日期的月份所有日期
      参数:
      date - 日期
      返回:
      回本月的所有日期 默认格式
    • getMonths

      public static String[] getMonths(Date date, String format)
      根据指定日期的月份所有日期
      参数:
      date - 日期
      format - 日期格式
      返回:
      回本月的所有日期
    • getYear

      public static int getYear(int number)
      取得当前日期的N年后的日期(如果想获得前几年的日期用-number) 默认格式
      参数:
      number - N年
      返回:
      N年的日期
    • getYear

      public static int getYear(String date, int number)
      取得当前日期的N年后的日期(如果想获得前几年的日期用-number)
      参数:
      date - 日期字符串
      number - N年
      返回:
      N年的日期
    • getYear

      public static int getYear(String date, int number, String format)
      取得当前日期的N年后的日期(如果想获得前几年的日期用-number)
      参数:
      date - 日期字符串
      number - N天
      format - 日期格式
      返回:
      N天的日期
    • getYear

      public static int getYear(Date date, int number)
      取得当前日期的N年后的日期(如果想获得前几年的日期用-number)
      参数:
      date - 日期
      number - N年
      返回:
      N年的日期
    • format

      public static String format(String src, String srcfmt, String desfmt)
      日期字符串格式转换
      参数:
      src - 日期字符串
      srcfmt - 源日期格式
      desfmt - 目标日期格式
      返回:
      转换后的日期
    • getYear

      public static int getYear(Date date)
      取指定日期的年份
      参数:
      date - 日期
      返回:
    • getMonth

      public static int getMonth(Date date)
      取指定日期的月份
      参数:
      date - 日期
      返回:
    • getDay

      public static int getDay(Date date)
      取指定日期月份的日
      参数:
      date - 日期
      返回:
    • getHour

      public static int getHour(Date date)
      获取当前 时
      参数:
      date - 日期
      返回:
    • getMinute

      public static int getMinute(Date date)
      获取当前 分
      参数:
      date - 日期
      返回:
    • getSecond

      public static int getSecond(Date date)
      获取当前 秒
      参数:
      date - 日期
      返回:
    • getYear

      public static int getYear()
      获取当前 年
      返回:
    • getMonth

      public static int getMonth()
      获取当前 月
      返回:
    • getDay

      public static int getDay()
      获取当前月份的 日
      返回:
    • getHour

      public static int getHour()
      获取当前 时
      返回:
    • getMinute

      public static int getMinute()
      获取当前 分
      返回:
    • getSecond

      public static int getSecond()
      获取当前 秒
      返回:
    • getMonthHaveDay

      public static int getMonthHaveDay()
      获得当前月份有几天
      返回:
      几天
    • getMonthHaveDay

      public static int getMonthHaveDay(int month)
      获得增加指定月份有几天
      参数:
      month - 增加的月份 本月填0 上个月填 -1 下个月填1
      返回:
      几天
    • getMonthHaveDay

      public static int getMonthHaveDay(Date date)
      获得指定月份有几天
      参数:
      date - 日期
      返回:
      几天
    • getYearHaveDay

      public static int getYearHaveDay()
      获得当前年份有几天
      返回:
      几天
    • getYearHaveDay

      public static int getYearHaveDay(Date date)
      获得指定年份有几天
      参数:
      date - 日期
      返回:
      几天
    • diff

      public static long diff(long time)
      根据传进来的时间算出与现在时间的差值
      参数:
      time - 传入的时间
      返回:
      与当前时间差
    • dura

      public static long dura()
      调用差异时间 按线程保存调用时间每次调用返回上次调用与本次相差时间
      返回:
    • time

      public static int time()
      获得当前时间 秒 System.currentTimeMillis()/1000
      返回:
      时间戳
    • now

      public static long now()
      获得当前时间 毫秒 System.currentTimeMillis()
      返回:
      时间戳
    • secondToTime

      public static String secondToTime(int time)
      转换时间到字符串格式 例如 输入300 转成00:05:00
      参数:
      time - 要转换的时间 单位秒
      返回:
      转换完格式的字符串