类 DateTime

java.lang.Object
cn.vorbote.core.time.DateTime
所有已实现的接口:
Serializable, Comparable<DateTime>

public final class DateTime extends Object implements Comparable<DateTime>, Serializable
DateTime class supports useful methods to times. The processing of date and time makes us particularly troubled in Java, so we developed the DateTime class and TimeSpan class that refer to the Date processing mechanism of the Dotnet platform. These classes are developed based on Java timestamp and the Calendar class of the Java platform, and it is convenient to use by encapsulating some convenient methods.
作者:
vorbote
另请参阅:
  • 构造器概要

    构造器
    构造器
    说明
    Generate a new DateTime instance of current time.
    DateTime(int year, int month, int date)
    Generate a specified DateTime instance of the date.
    DateTime(int year, int month, int date, int hour, int minute, int second)
    Generate a specified DateTime instance of the date.
    DateTime(long timestamp)
    Build a DateTime instance by java timestamp or unix timestamp.
    DateTime(long timestamp, boolean useMillisecond)
    Common constructor for timestamp.
    DateTime(Calendar calendar)
    Generate a new DateTime instance of current time.
    DateTime(Date date)
    Generate a new DateTime instance of current time.
  • 方法概要

    修饰符和类型
    方法
    说明
    Add the specific time to the DateTime instance.
    addDays(double days)
    Returns a new DateTime that adds the specified number of days to the value of this instance.
    addHours(double hours)
    Returns a new DateTime that adds the specified number of hours to the value of this instance.
    addMinutes(double minutes)
    Returns a new DateTime that adds the specified number of hours to the value of this instance.
    addMonths(int months)
    Returns a new DateTime that adds the specified number of months to the value of this instance.
    addSeconds(int seconds)
    Returns a new DateTime that adds the specified number of seconds to the value of this instance.
    addYears(int years)
    Returns a new DateTime that adds the specified number of years to the value of this instance.
    int
    Compares this object with the specified object for order.
    boolean
    Returns a value indicating whether the value of this instance is equal to the value of the specified DateTime instance.
    long
    Getter for timestamp, returns a unix timestamp.
    int
    Generate a hash code of this object.
    boolean
    Returns an indication whether the specified year is a leap year.
    long
    Get the Java Timestamp of this (@code DateTime} instance.
    A DateTime instance minus another instance will return a TimeSpan instance, this TimeSpan instance will tell you how many days, hours, minutes, seconds and milliseconds between them.
    Minus the specific time to the DateTime instance.
    static DateTime
    now()
    Get the current Date and Time.
    Get pattern for this datetime.
    pattern(String pattern)
    Set pattern for this datetime.
    long
    Get the timestamp.
    timestamp(long timestamp)
    Set the timestamp.
    Convert DateTime instance to Calendar instance.
    Convert DateTime instance to Date instance.
    This method o.toString() will convert the timestamp to a string time expression in the specified format.
    long
    Get the Unix Timestamp of this current time.

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

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

    • DateTime

      public DateTime()
      Generate a new DateTime instance of current time.
    • DateTime

      public DateTime(long timestamp, boolean useMillisecond)
      Common constructor for timestamp.
      参数:
      timestamp - The timestamp, no matter use unix timestamp or java timestamp.
      useMillisecond - If this timestamp uses millisecond, please specify this to true, otherwise false.
    • DateTime

      public DateTime(long timestamp)
      Build a DateTime instance by java timestamp or unix timestamp.
      参数:
      timestamp - Unix Timestamp.
    • DateTime

      public DateTime(Date date)
      Generate a new DateTime instance of current time.
      参数:
      date - A Date instance.
    • DateTime

      public DateTime(Calendar calendar)
      Generate a new DateTime instance of current time.
      参数:
      calendar - A Calendar instance.
    • DateTime

      public DateTime(int year, int month, int date)
      Generate a specified DateTime instance of the date.
      参数:
      year - The year (1 through 9999).
      month - The month (1 through 12).
      date - The day (1 through the number of days in month).
    • DateTime

      public DateTime(int year, int month, int date, int hour, int minute, int second)
      Generate a specified DateTime instance of the date.
      参数:
      year - The year (1 through 9999).
      month - The month (1 through 12).
      date - The day (1 through the number of days in month).
      hour - The hour (0 through 23).
      minute - The minute (0 through 59).
      second - The second (0 through 59).
  • 方法详细资料

    • getTimestamp

      public long getTimestamp()
      Getter for timestamp, returns a unix timestamp.
      返回:
      Unix timestamp.
    • unix

      public long unix()
      Get the Unix Timestamp of this current time.
      返回:
      The Unix Timestamp of this DateTime instance.
    • java

      public long java()
      Get the Java Timestamp of this (@code DateTime} instance.
      返回:
      The Java Timestamp of this DateTime instance, but will lose the millisecond.
    • add

      public DateTime add(TimeSpan ts)
      Add the specific time to the DateTime instance.
      参数:
      ts - Time Span.
      返回:
      The time after added this TimeSpan.
    • addDays

      public DateTime addDays(double days)
      Returns a new DateTime that adds the specified number of days to the value of this instance.
      参数:
      days - A number of whole and fractional days. The value parameter can be negative or positive.
      返回:
      An object whose value is the sum of the date and time represented by this instance and the number of days represented by value.
    • addHours

      public DateTime addHours(double hours)
      Returns a new DateTime that adds the specified number of hours to the value of this instance.
      参数:
      hours - A number of whole and fractional hours. The value parameter can be negative or positive.
      返回:
      An object whose value is the sum of the date and time represented by this instance and the number of hours represented by value.
    • addMinutes

      public DateTime addMinutes(double minutes)
      Returns a new DateTime that adds the specified number of hours to the value of this instance.
      参数:
      minutes - A number of whole and fractional minutes. The value parameter can be negative or positive.
      返回:
      An object whose value is the sum of the date and time represented by this instance and the number of minutes represented by value.
    • addMonths

      public DateTime addMonths(int months)
      Returns a new DateTime that adds the specified number of months to the value of this instance.
      参数:
      months - A number of months. The parameter can be negative or positive.
      返回:
      An object whose value is the sum of the date and time represented by this instance and months.
    • addSeconds

      public DateTime addSeconds(int seconds)
      Returns a new DateTime that adds the specified number of seconds to the value of this instance.
      参数:
      seconds - A number of whole and fractional seconds. The value parameter can be negative or positive.
      返回:
      An object whose value is the sum of the date and time represented by this instance and the number of seconds represented by value.
    • addYears

      public DateTime addYears(int years)
      Returns a new DateTime that adds the specified number of years to the value of this instance.
      参数:
      years - A number of years. The value parameter can be negative or positive.
      返回:
      An object whose value is the sum of the date and time represented by this instance and the number of years represented by value.
    • minus

      public DateTime minus(TimeSpan ts)
      Minus the specific time to the DateTime instance.
      参数:
      ts - Time Span.
      返回:
      The time after added this TimeSpan.
    • minus

      public TimeSpan minus(DateTime time)
      A DateTime instance minus another instance will return a TimeSpan instance, this TimeSpan instance will tell you how many days, hours, minutes, seconds and milliseconds between them.
      参数:
      time - Another DateTime instance
      返回:
      A TimeSpan instance which will tell you how many days, hours, minutes, seconds and milliseconds between them.
    • pattern

      public DateTime pattern(String pattern)
      Set pattern for this datetime.
      参数:
      pattern - The formatted String.
      返回:
      The DateTime instance itself.
    • pattern

      public String pattern()
      Get pattern for this datetime.
      返回:
      The pattern String.
    • timestamp

      public DateTime timestamp(long timestamp)
      Set the timestamp.
      参数:
      timestamp - The timestamp.
      返回:
      The DateTime instance itself.
    • timestamp

      public long timestamp()
      Get the timestamp.
      返回:
      The timestamp.
      另请参阅:
    • toString

      public String toString()
      This method o.toString() will convert the timestamp to a string time expression in the specified format.
      覆盖:
      toString 在类中 Object
      返回:
      A string time expression.
    • compareTo

      public int compareTo(DateTime o)
      Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
      指定者:
      compareTo 在接口中 Comparable<DateTime>
      参数:
      o - the object to be compared.
      返回:
      a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
      抛出:
      NullPointerException - if the specified object is null
      ClassCastException - if the specified object's type prevents it from being compared to this object.
    • equals

      public boolean equals(Object o)
      Returns a value indicating whether the value of this instance is equal to the value of the specified DateTime instance.
      覆盖:
      equals 在类中 Object
      参数:
      o - The object to compare to this instance.
      返回:
      True if the value parameter equals the value of this instance; Otherwise, false.
    • hashCode

      public int hashCode()
      Generate a hash code of this object.
      覆盖:
      hashCode 在类中 Object
      返回:
      The hash code of this object.
    • now

      public static DateTime now()
      Get the current Date and Time.
      返回:
      The current Date and Time.
      另请参阅:
    • isLeapYear

      public boolean isLeapYear()
      Returns an indication whether the specified year is a leap year.
      返回:
      An indication whether the specified year is a leap year.
    • toDate

      public Date toDate()
      Convert DateTime instance to Date instance.
      返回:
      Date instance.
    • toCalendar

      public Calendar toCalendar()
      Convert DateTime instance to Calendar instance.
      返回:
      Calendar instance.