程序包 cn.vorbote.time
类 DateTime
java.lang.Object
cn.vorbote.time.DateTime
- 所有已实现的接口:
Serializable,Comparable<DateTime>
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 thills@vorbote.cn
- 另请参阅:
-
构造器概要
构造器构造器说明DateTime()Generate a newDateTimeinstance ofcurrenttime.DateTime(int year, int month, int date) Generate a specifiedDateTimeinstance of the date.DateTime(int year, int month, int date, int hour, int minute, int second) Generate a specifiedDateTimeinstance of the date.DateTime(int year, int month, int date, int hour, int minute, int second, int mills) Generate a specifiedDateTimeinstance of the date.DateTime(long timestamp) Build aDateTimeinstance by java timestamp or unix timestamp.Generate a new DateTime instance ofcurrenttime.Generate a new DateTime instance ofcurrenttime. -
方法概要
修饰符和类型方法说明Add the specific time to theDateTimeinstance.AddDays(double days) Returns a newDateTimethat adds the specified number of days to the value of this instance.AddHours(double hours) Returns a newDateTimethat adds the specified number of hours to the value of this instance.AddMilliseconds(int milliseconds) Returns a newDateTimethat adds the specified number of hours to the value of this instance.AddMinutes(double minutes) Returns a newDateTimethat adds the specified number of hours to the value of this instance.AddMonths(int months) Returns a newDateTimethat adds the specified number of months to the value of this instance.AddSeconds(int seconds) Returns a newDateTimethat adds the specified number of seconds to the value of this instance.AddYears(int years) Returns a newDateTimethat adds the specified number of years to the value of this instance.intCompares this object with the specified object for order.intCompares this object with the specified object for order.booleanbooleanReturns a value indicating whether the value of this instance is equal to the value of the specifiedDateTimeinstance.longGetter for timestamp, returns a unix timestamp.inthashCode()booleanReturns an indication whether the specified year is a leap year.ADateTimeinstance minus another instance will return aTimeSpaninstance, thisTimeSpaninstance will tell you how many days, hours, minutes, seconds and milliseconds between them.Minus the specific time to theDateTimeinstance.static DateTimeNow()Get the current Date and Time.Pattern()Get pattern for this datetime.voidSet pattern for this datetime.longGet the timestamp.voidTimestamp(long timestamp) Set the timestamp.ConvertDateTimeinstance toCalendarinstance.ToDate()ConvertDateTimeinstance toDateinstance.toString()This methodo.toString()will convert the timestamp to a string time expression in the specified format.ToString()This methodo.toString()will convert the timestamp to a string time expression in the specified format.longUnix()Get the Unix Timestamp of this current time.
-
构造器详细资料
-
DateTime
public DateTime()Generate a newDateTimeinstance ofcurrenttime. -
DateTime
public DateTime(long timestamp) Build aDateTimeinstance by java timestamp or unix timestamp.- 参数:
timestamp- Unix Timestamp or Java Timestamp.
-
DateTime
Generate a new DateTime instance ofcurrenttime.- 参数:
date- ADateinstance.
-
DateTime
Generate a new DateTime instance ofcurrenttime.- 参数:
calendar- ACalendarinstance.
-
DateTime
public DateTime(int year, int month, int date) Generate a specifiedDateTimeinstance 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 specifiedDateTimeinstance 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).
-
DateTime
public DateTime(int year, int month, int date, int hour, int minute, int second, int mills) Generate a specifiedDateTimeinstance 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).mills- The mills (0 through 999).
-
-
方法详细资料
-
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
DateTimeinstance.
-
Add
Add the specific time to theDateTimeinstance.- 参数:
ts- Time Span.- 返回:
- The time after added this
TimeSpan.
-
AddDays
Returns a newDateTimethat 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
Returns a newDateTimethat 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.
-
AddMilliseconds
Returns a newDateTimethat adds the specified number of hours to the value of this instance.- 参数:
milliseconds- A number of whole and fractional millisecond. 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 milliseconds represented by value.
-
AddMinutes
Returns a newDateTimethat 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
Returns a newDateTimethat adds the specified number of months to the value of this instance.- 参数:
months- A number of months. The months 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
Returns a newDateTimethat 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
Returns a newDateTimethat 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
Minus the specific time to theDateTimeinstance.- 参数:
ts- Time Span.- 返回:
- The time after added this
TimeSpan.
-
Minus
ADateTimeinstance minus another instance will return aTimeSpaninstance, thisTimeSpaninstance will tell you how many days, hours, minutes, seconds and milliseconds between them.- 参数:
time- AnotherDateTimeinstance- 返回:
- A
TimeSpaninstance which will tell you how many days, hours, minutes, seconds and milliseconds between them.
-
Pattern
Set pattern for this datetime.- 参数:
pattern- The formatted String.
-
Pattern
Get pattern for this datetime.- 返回:
- The pattern String.
-
Timestamp
public void Timestamp(long timestamp) Set the timestamp.- 参数:
timestamp- The timestamp.
-
Timestamp
public long Timestamp()Get the timestamp.- 返回:
- The timestamp.
-
toString
This methodo.toString()will convert the timestamp to a string time expression in the specified format. -
ToString
This methodo.toString()will convert the timestamp to a string time expression in the specified format.- 返回:
- A string time expression.
-
compareTo
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 nullClassCastException- if the specified object's type prevents it from being compared to this object.
-
CompareTo
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.- 参数:
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 nullClassCastException- if the specified object's type prevents it from being compared to this object.
-
Equals
Returns a value indicating whether the value of this instance is equal to the value of the specifiedDateTimeinstance.- 参数:
o- The object to compare to this instance.- 返回:
- True if the value parameter equals the value of this instance; Otherwise, false.
-
equals
-
hashCode
public int hashCode() -
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
ConvertDateTimeinstance toDateinstance.- 返回:
Dateinstance.
-
ToCalendar
ConvertDateTimeinstance toCalendarinstance.- 返回:
Calendarinstance.
-