System.DateTime Struct
Summary
Represents an instance of a date and time. This type is immutable.
The DateTime structure is used to represent a date and time value. The value of a DateTime object is the number ofticks that have passed since 12:00:00 midnight, January 1, 0001 C.E. in the Gregorian calendar, plus an additional value that indicates whether the DateTime object represents a local time, the Coordinated Universal Time (UTC), or a time in a custom time zone. The maximum value of DateTime is 12/31/9999 11:59:59 P.M.
Properties
-
Date
Gets the date component of this instance.
-
Day
Gets the day of the month represented by this instance.
-
DayOfWeek
Gets the day of the week represented by this instance.
-
DayOfYear
Gets the day of the year represented by this instance.
-
Hour
Gets the hour component of the value of this instance.
-
Kind
Gets a value that indicates whether the current DateTime object represents a local time, Coordinated Universal Time (UTC), or is not a time of day.
-
Millisecond
Gets the millisecond component of the value of this instance.
-
Minute
Gets the minute component of the value of this instance.
-
Month
Gets the month component of the value of this instance.
-
Second
Gets the second component of the value of this instance.
-
Ticks
Gets the value of this instance expressed as the number of ticks.
-
TimeOfDay
Gets the time-of-day component of this instance.
-
Year
Gets the year component of the value of this instance.
Methods
-
AddDays(double value)
Returns a new DateTime instance that is offset by the specified number of days.
-
AddHours(double value)
Returns a new DateTime instance that is offset by the specified number of hours.
-
AddMilliseconds(double value)
Returns a new DateTime instance that is offset by the specified number of milliseconds.
-
AddMinutes(double value)
Returns a new DateTime instance that is offset by the specified number of minutes.
-
AddMonths(int months)
Returns a new DateTime instance that is offset by the specified number of months.
-
AddSeconds(double value)
Returns a new DateTime instance that is offset by the specified number of seconds.
-
AddTicks(long value)
Returns a new DateTime instance that is offset by the specified number of ticks.
-
AddYears(int value)
Returns a new DateTime instance that is offset by the specified number of years.
-
CompareTo(object value)
Compares the current instance to another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position as the other object.
-
Equals(object obj)
Determines whether the current instance and a specified object represent the same date and time.
-
Parse(string s)
Converts the string representation of a date and time to its DateTime equivalent.
-
ParseExact(string s, string format, IFormatProvider provider)
Converts the string representation of a date and time to its DateTime equivalent using the specified format and culture-specific format information. A return value indicates whether the conversion succeeded.
-
Subtract(DateTime value)
Returns a TimeSpan value that represents the difference between the current and specified DateTime instances.
-
ToString()
Converts the value of this instance to its equivalent string representation.
-
ToString(string format)
Converts the value of this instance to its equivalent string representation using the specified format.
Operators
-
== (DateTime, DateTime)
Indicates whether two DateTime instances represent the same point in time.
-
!= (DateTime, DateTime)
Indicates whether two DateTime instances represent different points in time.
-
< (DateTime, DateTime)
Indicates whether the first specified DateTime instance is earlier than the second specified DateTime instance.
-
> (DateTime, DateTime)
Indicates whether the first specified DateTime instance is later than the second specified DateTime instance.
-
<= (DateTime, DateTime)
Indicates whether the first specified DateTime instance is earlier than or equal to the second specified DateTime instance.
-
>= (DateTime, DateTime)
Indicates whether the first specified DateTime instance is later than or equal to the second specified DateTime instance.
-
- (DateTime, DateTime)
Subtracts one specified DateTime instance from another and returns a TimeSpan instance that represents the difference.
Static Members
-
MinValue
Gets the smallest possible value for DateTime. This field is read-only.
-
MaxValue
Gets the largest possible value for DateTime. This field is read-only.
-
Now
Gets a DateTime object that is set to the current date and time on this computer, expressed as the local time.
-
UtcNow
Gets a DateTime object that is set to the current date and time on this computer, expressed as Coordinated Universal Time (UTC).
-
DaysInMonth(int year, int month)
Returns the number of days in the specified month and year.
-
IsLeapYear(int year)
Determines whether the specified year is a leap year.
-
Parse(string s, IFormatProvider provider)
Converts the string representation of a date and time to its DateTime equivalent using the specified format provider.
-
Parse(string s, IFormatProvider provider, DateTimeStyles styles)
Converts the string representation of a date and time to its DateTime equivalent using the specified format provider and styles.
-
Today
Gets the current date and time on this computer, expressed as the local time.