DateTime

DateTime class

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

Constructors

NameDescription
DateTimeInitializes a new instance of the DateTime object to the specified year, month, and day.
DateTimeInitializes a new instance of the DateTime object to the specified year, month, day, hour, minute, and second.
DateTimeInitializes a new instance of the DateTime object to the specified year, month, day, hour, minute, second, and milliseco
DateTimeInitializes a new instance of the DateTime object to the specified Date object
DateTimeInitializes a new instance of the DateTime object to the specified Calendar object

Methods

NameDescription
toDateConverts the value of the current DateTime object to Date object.
toCalendarConverts the value of the current DateTime object to Calendar object.
toUniversalTimeConverts the value of the current DateTime object to Coordinated Universal Time(UTC).
toLocalTimeConverts the value of the current DateTime object to local time.
addDaysAdds the specified number of days to the value of this instance.
addHoursAdds the specified number of hours to the value of this instance.
addMillisecondsAdds the specified number of milliseconds to the value of this instance.
addMinutesAdds the specified number of minutes to the value of this instance.
addMonthsAdds the specified number of months to the value of this instance.
addSecondsAdds the specified number of seconds to the value of this instance.
addYearsAdds the specified number of years to the value of this instance.
compareToCompares the value of this instance to a specified object that contains a specified DateTime value, and returns an integ
hashCodeReturns the hash code for this instance.
equalsReturns a value indicating whether this instance is equal to a specified object.
getDayGets the day of the month represented by this instance.
getDayOfWeekGets the day of the week represented by this instance.
getDayOfYearGets the day of the year represented by this instance.
getHourGets the hour component of the date represented by this instance.
getMillisecondGets the milliseconds component of the date represented by this instance.
getMinuteGets the minute component of the date represented by this instance.
getMonthGets the month component of the date represented by this instance.
getNowGets a DateTime object that is set to the current date and time on this computer, expressed as the local time.
getSecondGets the seconds component of the date represented by this instance.
getYearGets the year component of the date represented by this instance.
toStringConverts the value of the current DateTime object to its equivalent string representation.

DateTime(year, month, day) (1 of 5)

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

ParameterTypeDescription
yearintThe year (1 through 9999).
monthintThe month (1 through 12).
dayintThe day (1 through the number of days in month).

DateTime(year, month, day, hour, minute, second) (2 of 5)

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

ParameterTypeDescription
yearintThe year (1 through 9999).
monthintThe month (1 through 12).
dayintThe day (1 through the number of days in month).
hourintThe hours (0 through 23).
minuteintThe minutes (0 through 59).
secondintThe seconds (0 through 59).

DateTime(year, month, day, hour, minute, second, millisecond) (3 of 5)

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

ParameterTypeDescription
yearintThe year (1 through 9999).
monthintThe month (1 through 12).
dayintThe day (1 through the number of days in month).
hourintThe hours (0 through 23).
minuteintThe minutes (0 through 59).
secondintThe seconds (0 through 59).
millisecondintThe milliseconds (0 through 999).

DateTime(date) (4 of 5)

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

ParameterTypeDescription
dateDateThe Date object

DateTime(cld) (5 of 5)

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

ParameterTypeDescription
cldCalendarThe Calendar object

toDate()

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

Returns: Date object

toCalendar()

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

Returns: Calendar object

toUniversalTime()

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

Returns: A DateTime object of UTC

toLocalTime()

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

Returns: A DateTime object of local

addDays(value)

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

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

Returns: 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
valuefloatA number of whole and fractional hours. The value parameter can be negative or positive.

Returns: 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
valuefloatA 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: 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
valuefloatA number of whole and fractional minutes. The value parameter can be negative or positive.

Returns: 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
monthsintA number of months. The months parameter can be negative or positive.

Returns: 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
valuefloatA number of whole and fractional seconds. The value parameter can be negative or positive.

Returns: 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
valueintA number of years. The value parameter can be negative or positive.

Returns: 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) (1 of 2)

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: 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) (2 of 2)

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: 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.

hashCode()

Returns the hash code for this instance.

Returns: A 32-bit signed integer hash code.

equals(value)

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

ParameterTypeDescription
valueObjectAn object to compare to this instance.

Returns: 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: The day component, expressed as a value between 1 and 31.

getDayOfWeek()

Gets the day of the week represented by this instance.

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

getDayOfYear()

Gets the day of the year represented by this instance.

Returns: 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: The hour component, expressed as a value between 0 and 23.

getMillisecond()

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

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

getMinute()

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

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

getMonth()

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

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

getNow()

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

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

getSecond()

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

Returns: The seconds, between 0 and 59.

getYear()

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

Returns: The year, between 1 and 9999.

toString()

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

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