DateTime

DateTime class

Represents an instant in time, typically expressed as a date and time of day.

new DateTime(year, month, day)

Initializes a new instance of the DateTime object to the specified year, month, and day.

Methods

NameDescription
addDays(value)Adds the specified number of days to the value of this instance.
addHours(value)Adds the specified number of hours to the value of this instance.
addMilliseconds(value)Adds the specified number of milliseconds to the value of this instance.
addMinutes(value)Adds the specified number of minutes to the value of this instance.
addMonths(months)Adds the specified number of months to the value of this instance.
addSeconds(value)Adds the specified number of seconds to the value of this instance.
addYears(value)Adds the specified number of years to the value of this instance.
compareTo(value)Compares the value of this instance to a specified object that contains a specified DateTime value, and returns an integ
compareTo(value)Compares the value of this instance to a specified DateTime value and returns an integer that indicates whether this ins
constructor_overload$1(year, month, day, hour, minute, second)Initializes a new instance of the DateTime object to the specified year, month, day, hour, minute, and second.
constructor_overload$2(year, month, day, hour, minute, second, millisecond)Initializes a new instance of the DateTime object to the specified year, month, day, hour, minute, second, and milliseco
constructor_overload$3(date)Initializes a new instance of the DateTime object to the specified Date object
constructor_overload$4(cld)Initializes a new instance of the DateTime object to the specified Calendar object
equals(value)Returns a value indicating whether this instance is equal to a specified object.
getDay()Gets the day of the month represented by this instance.
getDayOfWeek()Gets the day of the week represented by this instance.
getDayOfYear()Gets the day of the year represented by this instance.
getHour()Gets the hour component of the date represented by this instance.
getMillisecond()Gets the milliseconds component of the date represented by this instance.
getMinute()Gets the minute component of the date represented by this instance.
getMonth()Gets the month component of the date represented by this instance.
getSecond()Gets the seconds component of the date represented by this instance.
getYear()Gets the year component of the date represented by this instance.
hashCode()Returns the hash code for this instance.
toCalendar()Converts the value of the current DateTime object to Calendar object.
toDate()Converts the value of the current DateTime object to Date object.
toLocalTime()Converts the value of the current DateTime object to local time.
toString()Converts the value of the current DateTime object to its equivalent string representation.
toUniversalTime()Converts the value of the current DateTime object to Coordinated Universal Time(UTC).
getNow() (static)Gets a DateTime object that is set to the current date and time on this computer, expressed as the local time.

addDays(value)

Adds the specified number of days to the value of this instance.

ParameterTypeDescription
valueNumberA number of whole and fractional days. The value parameter can be negative or positive.

Returns: DateTime — DateTime A DateTime object whose value is the sum of the date and time represented by this instance and the number of days represented by value.

addHours(value)

Adds the specified number of hours to the value of this instance.

ParameterTypeDescription
valueNumberA number of whole and fractional hours. The value parameter can be negative or positive.

Returns: DateTime — DateTime A DateTime object whose value is the sum of the date and time represented by this instance and the number of hours represented by value.

addMilliseconds(value)

Adds the specified number of milliseconds to the value of this instance.

ParameterTypeDescription
valueNumberA number of whole and fractional milliseconds. The value parameter can be negative or positive. Note that this value is rounded to the nearest integer.

Returns: DateTime — DateTime A DateTime object whose value is the sum of the date and time represented by this instance and the number of milliseconds represented by value.

addMinutes(value)

Adds the specified number of minutes to the value of this instance.

ParameterTypeDescription
valueNumberA number of whole and fractional minutes. The value parameter can be negative or positive.

Returns: DateTime — DateTime A DateTime object whose value is the sum of the date and time represented by this instance and the number of minutes represented by value.

addMonths(months)

Adds the specified number of months to the value of this instance.

ParameterTypeDescription
monthsNumberA number of months. The months parameter can be negative or positive.

Returns: DateTime — DateTime A DateTime object whose value is the sum of the date and time represented by this instance and months.

addSeconds(value)

Adds the specified number of seconds to the value of this instance.

ParameterTypeDescription
valueNumberA number of whole and fractional seconds. The value parameter can be negative or positive.

Returns: DateTime — DateTime A DateTime object whose value is the sum of the date and time represented by this instance and the number of seconds represented by value.

addYears(value)

Adds the specified number of years to the value of this instance.

ParameterTypeDescription
valueNumberA number of years. The value parameter can be negative or positive.

Returns: DateTime — DateTime A DateTime object whose value is the sum of the date and time represented by this instance and the number of years represented by value.

compareTo(value)

Compares the value of this instance to a specified object that contains a specified DateTime value, and returns an integer that indicates whether this instance is earlier than, the same as, or later than the specified DateTime value.

ParameterTypeDescription
valueObjectA boxed DateTime object to compare, or null.

Returns: Number — Number A signed number indicating the relative values of this instance and value. Value Description Less than zero This instance is earlier than value. Zero This instance is the same as value. Greater than zero This instance is later than value, or value is null.

compareTo(value)

Compares the value of this instance to a specified DateTime value and returns an integer that indicates whether this instance is earlier than, the same as, or later than the specified DateTime value.

ParameterTypeDescription
valueDateTimeA DateTime object to compare.

Returns: Number — Number A signed number indicating the relative values of this instance and the value parameter. Value Description Less than zero This instance is earlier than value. Zero This instance is the same as value. Greater than zero This instance is later than value.

constructor_overload$1(year, month, day, hour, minute, second)

Initializes a new instance of the DateTime object to the specified year, month, day, hour, minute, and second.

ParameterTypeDescription
yearNumberThe year (1 through 9999).
monthNumberThe month (1 through 12).
dayNumberThe day (1 through the number of days in month).
hourNumberThe hours (0 through 23).
minuteNumberThe minutes (0 through 59).
secondNumberThe seconds (0 through 59).

constructor_overload$2(year, month, day, hour, minute, second, millisecond)

Initializes a new instance of the DateTime object to the specified year, month, day, hour, minute, second, and millisecond.

ParameterTypeDescription
yearNumberThe year (1 through 9999).
monthNumberThe month (1 through 12).
dayNumberThe day (1 through the number of days in month).
hourNumberThe hours (0 through 23).
minuteNumberThe minutes (0 through 59).
secondNumberThe seconds (0 through 59).
millisecondNumberThe milliseconds (0 through 999).

constructor_overload$3(date)

Initializes a new instance of the DateTime object to the specified Date object

ParameterTypeDescription
dateDateThe Date object

constructor_overload$4(cld)

Initializes a new instance of the DateTime object to the specified Calendar object

ParameterTypeDescription
cldCalendarThe Calendar object

equals(value)

Returns a value indicating whether this instance is equal to a specified object.

ParameterTypeDescription
valueObjectAn object to compare to this instance.

Returns: boolean — boolean true if value is an instance of DateTime and equals the value of this instance; otherwise, false.

getDay()

Gets the day of the month represented by this instance.

Returns: Number — Number The day component, expressed as a value between 1 and 31.

getDayOfWeek()

Gets the day of the week represented by this instance.

Returns: Number — Number the day of the week of this DateTime value.

getDayOfYear()

Gets the day of the year represented by this instance.

Returns: Number — Number The day of the year, expressed as a value between 1 and 366.

getHour()

Gets the hour component of the date represented by this instance.

Returns: Number — Number The hour component, expressed as a value between 0 and 23.

getMillisecond()

Gets the milliseconds component of the date represented by this instance.

Returns: Number — Number The milliseconds component, expressed as a value between 0 and 999.

getMinute()

Gets the minute component of the date represented by this instance.

Returns: Number — Number The minute component, expressed as a value between 0 and 59.

getMonth()

Gets the month component of the date represented by this instance.

Returns: Number — Number The month component, expressed as a value between 1 and 12.

getSecond()

Gets the seconds component of the date represented by this instance.

Returns: Number — Number The seconds, between 0 and 59.

getYear()

Gets the year component of the date represented by this instance.

Returns: Number — Number The year, between 1 and 9999.

hashCode()

Returns the hash code for this instance.

Returns: Number — Number A 32-bit signed integer hash code.

toCalendar()

Converts the value of the current DateTime object to Calendar object.

Returns: Calendar — Calendar Calendar object

toDate()

Converts the value of the current DateTime object to Date object.

Returns: Date — Date Date object

toLocalTime()

Converts the value of the current DateTime object to local time.

Returns: DateTime — DateTime A DateTime object of local

toString()

Converts the value of the current DateTime object to its equivalent string representation.

Returns: String — String A string representation of the value of the current DateTime object.

toUniversalTime()

Converts the value of the current DateTime object to Coordinated Universal Time(UTC).

Returns: DateTime — DateTime A DateTime object of UTC

getNow() (static)

Gets a DateTime object that is set to the current date and time on this computer, expressed as the local time.

Returns: DateTime — DateTime A DateTime object whose value is the current local date and time.