← Interactive API Explorer
Namespace: System

DateTime

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

Properties (14)

DateTime Now
Gets a DateTime object that is set to the current date and time on this computer, expressed as the local time.
Value: An object whose value is the current local date and time.
DateTime UtcNow
Gets a DateTime object that is set to the current date and time on this computer, expressed as the Coordinated Universal Time (UTC).
Value: An object whose value is the current UTC date and time.
DateTimeKind Kind
Gets a value that indicates whether the time represented by this instance is based on local time, Coordinated Universal Time (UTC), or neither.
Value: One of the enumeration values that indicates what the current time represents. The default is Unspecified.
long Ticks
Gets the number of ticks that represent the date and time of this instance.
Value: The number of ticks that represent the date and time of this instance. The value is between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks.
int Year
Gets the year component of the date represented by this instance.
Value: The year, between 1 and 9999.
int Month
Gets the month component of the date represented by this instance.
Value: The month component, expressed as a value between 1 and 12.
int Day
Gets the day of the month represented by this instance.
Value: The day component, expressed as a value between 1 and 31.
int Hour
Gets the hour component of the date represented by this instance.
Value: The hour component, expressed as a value between 0 and 23.
int Minute
Gets the minute component of the date represented by this instance.
Value: The minute component, expressed as a value between 0 and 59.
int Second
Gets the seconds component of the date represented by this instance.
Value: The seconds component, expressed as a value between 0 and 59.
int Millisecond
Gets the milliseconds component of the date represented by this instance.
Value: The milliseconds component, expressed as a value between 0 and 999.
DayOfWeek DayOfWeek
Gets the day of the week represented by this instance.
Value: An enumerated constant that indicates the day of the week of this DateTime value.
DateTime Date
Gets the date component of this instance.
Value: A new object with the same date as this instance, and the time value set to 12:00:00 midnight (00:00:00).
TimeSpan TimeOfDay
Gets the time of day for this instance.
Value: A time interval that represents the fraction of the day that has elapsed since midnight.

Methods (19)

DateTime(Int64)Constructor
Initializes a new instance of the DateTime structure to a specified number of ticks.
ParameterDescription
ticksA 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.
DateTime(Int64,DateTimeKind)Constructor
Initializes a new instance of the DateTime structure to a specified number of ticks and to Coordinated Universal Time (UTC) or local time.
ParameterDescription
ticksA 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.
kindOne of the enumeration values that indicates whether ticks specifies a local time, Coordinated Universal Time (UTC), or neither.
DateTime(Int32,Int32,Int32)Constructor
Initializes a new instance of the DateTime structure to the specified year, month, and day.
ParameterDescription
yearThe year (1 through 9999).
monthThe month (1 through 12).
dayThe day (1 through the number of days in month).
DateTime(Int32,Int32,Int32,Int32,Int32,Int32)Constructor
Initializes a new instance of the DateTime structure to the specified year, month, day, hour, minute, and second.
ParameterDescription
yearThe year (1 through 9999).
monthThe month (1 through 12).
dayThe day (1 through the number of days in month).
hourThe hours (0 through 23).
minuteThe minutes (0 through 59).
secondThe seconds (0 through 59).
DateTime(Int32,Int32,Int32,Int32,Int32,Int32,DateTimeKind)Constructor
Initializes a new instance of the DateTime structure to the specified year, month, day, hour, minute, second, and Coordinated Universal Time (UTC) or local time.
ParameterDescription
yearThe year (1 through 9999).
monthThe month (1 through 12).
dayThe day (1 through the number of days in month).
hourThe hours (0 through 23).
minuteThe minutes (0 through 59).
secondThe seconds (0 through 59).
kindOne of the enumeration values that indicates whether year, month, day, hour, minute and second specify a local time, Coordinated Universal Time (UTC), or neither.
DateTime(Int32,Int32,Int32,Int32,Int32,Int32,Int32)Constructor
Initializes a new instance of the DateTime structure to the specified year, month, day, hour, minute, second, and millisecond.
ParameterDescription
yearThe year (1 through 9999).
monthThe month (1 through 12).
dayThe day (1 through the number of days in month).
hourThe hours (0 through 23).
minuteThe minutes (0 through 59).
secondThe seconds (0 through 59).
millisecondThe milliseconds (0 through 999).
DateTime(Int32,Int32,Int32,Int32,Int32,Int32,Int32,DateTimeKind)Constructor
Initializes a new instance of the DateTime structure to the specified year, month, day, hour, minute, second, millisecond, and Coordinated Universal Time (UTC) or local time.
ParameterDescription
yearThe year (1 through 9999).
monthThe month (1 through 12).
dayThe day (1 through the number of days in month).
hourThe hours (0 through 23).
minuteThe minutes (0 through 59).
secondThe seconds (0 through 59).
millisecondThe milliseconds (0 through 999).
kindOne of the enumeration values that indicates whether year, month, day, hour, minute, second, and millisecond specify a local time, Coordinated Universal Time (UTC), or neither.
bool IsLeapYear(Int32)
Returns an indication whether the specified year is a leap year.
ParameterDescription
yearA 4-digit year.
Returns: true if year is a leap year; otherwise, false.
int DaysInMonth(Int32,Int32)
Returns the number of days in the specified month and year.
ParameterDescription
yearThe year.
monthThe month (a number ranging from 1 to 12).
Returns: The number of days in month for the specified year. For example, if month equals 2 for February, the return value is 28 or 29 depending upon whether year is a leap year.
DateTime Parse(String)
Converts the string representation of a date and time to its DateTime equivalent by using the conventions of the current thread culture.
ParameterDescription
sA string that contains a date and time to convert. See The string to parse for more information.
Returns: An object that is equivalent to the date and time contained in s.
DateTime ToUniversalTime
Converts the value of the current DateTime object to Coordinated Universal Time (UTC).
Returns: An object whose Kind property is Utc, and whose value is the UTC equivalent to the value of the current DateTime object, or MaxValue if the converted value is too large to be represented by a DateTime object, or MinValue if the converted value is too small to be represented by a DateTime object.
DateTime AddMonths(Int32)
Returns a new DateTime that adds the specified number of months to the value of this instance.
ParameterDescription
monthsA 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.
DateTime AddYears(Int32)
Returns a new DateTime that adds the specified number of years to the value of this instance.
ParameterDescription
valueA 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.
DateTime AddTicks(Int64)
Returns a new DateTime that adds the specified number of ticks to the value of this instance.
ParameterDescription
valueA number of 100-nanosecond ticks. The value parameter can be positive or negative.
Returns: An object whose value is the sum of the date and time represented by this instance and the time represented by value.
DateTime AddDays(Double)
Returns a new DateTime that adds the specified number of days to the value of this instance.
ParameterDescription
valueA number of whole and fractional days. 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 days represented by value.
DateTime AddHours(Double)
Returns a new DateTime that adds the specified number of hours to the value of this instance.
ParameterDescription
valueA number of whole and fractional hours. 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 hours represented by value.
DateTime AddMinutes(Double)
Returns a new DateTime that adds the specified number of minutes to the value of this instance.
ParameterDescription
valueA number of whole and fractional minutes. 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 minutes represented by value.
DateTime AddSeconds(Double)
Returns a new DateTime that adds the specified number of seconds to the value of this instance.
ParameterDescription
valueA number of whole and fractional seconds. 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 seconds represented by value.
DateTime AddMilliseconds(Double)
Returns a new DateTime that adds the specified number of milliseconds to the value of this instance.
ParameterDescription
valueA 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: An object whose value is the sum of the date and time represented by this instance and the number of milliseconds represented by value.