Class NCDateTime
- java.lang.Object
-
- com.alachisoft.ncache.runtime.util.NCDateTime
-
public class NCDateTime extends java.lang.Object
Represents an instant in time, typically expressed as a date and time of day.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DaysTo1970
Number of days from 1/1/0001 to 12/31/1969static long
MaxTicks
MaxTicks is DaysTo10000 * TicksPerDay - 1;static java.util.Date
MaxValue
MaxValuestatic long
MinTicks
MinTicks of the Instancestatic java.util.Date
MinValue
MinValue is new Date of MinTicks
-
Constructor Summary
Constructors Constructor Description NCDateTime(int year, int month, int day, int hours, int minutes, int seconds, int milliseconds)
Initializes a new instance of the NCDateTime class to the specified year, month, day, hour, minute, second, and millisecond.NCDateTime(long ticks)
Initializes a new instance of the NCDateTime class to a specified number of ticks.NCDateTime(java.util.Date date)
Initializes a new instance of the NCDateTime class to the specified date.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDays(double value)
Adds the specified number of days to the value of this instance.java.util.Date
AddMonths(int months)
Returns a new Date that adds the specified number of months to the value of this instance.void
addTicks(long ticks)
Adds adds the specified number of ticks to the value of this instance.java.util.Date
AddYears(int value)
Returns a new Date that adds the specified number of years to the value of this instance.static int
DaysInMonth(int year, int month)
java.util.Date
getDate()
Returns the java.util.Date value corresponding to this NCDateTime instance.int
getDay()
Gets the day of the month represented by this instance.static java.util.Date
getDefaultDate()
Gets the default value of NCDateTime i.e.int
getHours()
Gets the hour component of the date represented by this instance.java.util.Date
getLocalizedDate()
Returns the java.util.Date value corresponding to this instance after converting to local time.long
getLocalizedTimeInTicks()
Gets the ticks corresponding to the current local time.int
getMilliseconds()
Gets the milliseconds component of the date represented by this instance.int
getMinutes()
Gets the minute component of the date represented by this instance.int
getMonth()
Gets the month component of the date represented by this instance.int
getSeconds()
Gets the seconds component of the date represented by this instance.long
getTicks()
Gets the number of ticks that represent the date and time of this instance.static java.util.Date
getUTCDate(java.util.Date date)
Gets an NCDateTime object that converts the specified date to UTC equivalent.static java.util.Date
getUTCNow()
Gets a DateTime object that is set to the current date and time on this computer, expressed as the Coordinated Universal Time (UTC).int
getYear()
Gets the year component of the date represented by this instance.
-
-
-
Field Detail
-
DaysTo1970
public static final int DaysTo1970
Number of days from 1/1/0001 to 12/31/1969- See Also:
- Constant Field Values
-
MinTicks
public static final long MinTicks
MinTicks of the Instance- See Also:
- Constant Field Values
-
MaxTicks
public static final long MaxTicks
MaxTicks is DaysTo10000 * TicksPerDay - 1;- See Also:
- Constant Field Values
-
MinValue
public static final java.util.Date MinValue
MinValue is new Date of MinTicks
-
MaxValue
public static final java.util.Date MaxValue
MaxValue
-
-
Constructor Detail
-
NCDateTime
public NCDateTime(int year, int month, int day, int hours, int minutes, int seconds, int milliseconds) throws java.lang.IllegalArgumentException
Initializes a new instance of the NCDateTime class to the specified year, month, day, hour, minute, second, and millisecond.- Parameters:
year
- The year (1 through 9999).month
- The month (1 through 12).day
- The day (1 through the number of days in month).hours
- The hours (0 through 23).minutes
- The minutes (0 through 59).seconds
- The seconds (0 through 59).milliseconds
- The milliseconds (0 through 999).- Throws:
java.lang.IllegalArgumentException
-
NCDateTime
public NCDateTime(java.util.Date date) throws java.lang.IllegalArgumentException
Initializes a new instance of the NCDateTime class to the specified date.- Parameters:
date
- The date that is to be set.- Throws:
java.lang.IllegalArgumentException
-
NCDateTime
public NCDateTime(long ticks)
Initializes a new instance of the NCDateTime class to a specified number of ticks.- Parameters:
ticks
- A date and time expressed in the number of 100-nanosecond intervals that have elapsed since January 1, 0001 at 00:00:00.000 in the Gregorian calendar.
-
-
Method Detail
-
addTicks
public void addTicks(long ticks)
Adds adds the specified number of ticks to the value of this instance.- Parameters:
ticks
- A number of 100-nanosecond ticks. The value parameter can be positive or negative.
-
getUTCNow
public static java.util.Date getUTCNow()
Gets a DateTime object that is set to the current date and time on this computer, expressed as the Coordinated Universal Time (UTC).- Returns:
- An object whose value is the current UTC date and time.
-
getUTCDate
public static java.util.Date getUTCDate(java.util.Date date) throws java.text.ParseException
Gets an NCDateTime object that converts the specified date to UTC equivalent.- Returns:
- An NCDateTime object whose value is converted to UTC date and time.
- Throws:
java.text.ParseException
-
getDay
public int getDay()
Gets the day of the month represented by this instance.- Returns:
- The day component, expressed as a value between 1 and 31.
-
getHours
public int getHours()
Gets the hour component of the date represented by this instance.- Returns:
- The hour component, expressed as a value between 0 and 23.
-
getMilliseconds
public int getMilliseconds()
Gets the milliseconds component of the date represented by this instance.- Returns:
- The milliseconds component, expressed as a value between 0 and 999.
-
getMinutes
public int getMinutes()
Gets the minute component of the date represented by this instance.- Returns:
- The minute component, expressed as a value between 0 and 59.
-
getMonth
public int getMonth()
Gets the month component of the date represented by this instance.- Returns:
- The month component, expressed as a value between 1 and 12.
-
getSeconds
public int getSeconds()
Gets the seconds component of the date represented by this instance.- Returns:
- The seconds component, expressed as a value between 0 and 59.
-
getYear
public int getYear()
Gets the year component of the date represented by this instance.- Returns:
- The year, between 1 and 9999.
-
AddYears
public java.util.Date AddYears(int value) throws java.lang.IllegalArgumentException
Returns a new Date that adds the specified number of years to the value of this instance.- Parameters:
value
- A number of years. The value parameter can be negative or positive.- Returns:
- An object whose value is the sum of the date and time represented by this instance and the number of years represented by value.
- Throws:
java.lang.IllegalArgumentException
-
AddMonths
public java.util.Date AddMonths(int months) throws java.lang.IllegalArgumentException
Returns a new Date that adds the specified number of months to the value of this instance.- Parameters:
months
- A number of months. The months parameter can be negative or positive.- Returns:
- An object whose value is the sum of the date and time represented by this instance and months.
- Throws:
java.lang.IllegalArgumentException
-
DaysInMonth
public static int DaysInMonth(int year, int month) throws java.lang.IllegalArgumentException
- Throws:
java.lang.IllegalArgumentException
-
getTicks
public long getTicks()
Gets the number of ticks that represent the date and time of this instance.- Returns:
- The number of ticks that represent the date and time of this instance. The value is between NCDateTime.MinValue.Ticks and NCDateTime.MaxValue.Ticks.
-
getDate
public java.util.Date getDate()
Returns the java.util.Date value corresponding to this NCDateTime instance.- Returns:
- The Date instance.
-
getLocalizedDate
public java.util.Date getLocalizedDate()
Returns the java.util.Date value corresponding to this instance after converting to local time.- Returns:
- The Date instance.
-
getLocalizedTimeInTicks
public long getLocalizedTimeInTicks()
Gets the ticks corresponding to the current local time.- Returns:
- The ticks corresponding to the current local time.
-
getDefaultDate
public static java.util.Date getDefaultDate()
Gets the default value of NCDateTime i.e. January 1, 0001 00:00:00- Returns:
- The date equivalent of default NCDateTime value.
-
addDays
public void addDays(double value)
Adds the specified number of days to the value of this instance.- Parameters:
value
- A number of whole and fractional days. The value parameter can be negative or positive.
-
-