DateTime Struct
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Represents an instant in time, typically expressed as a date and time of day.
public value class DateTime : IComparable, IComparable<DateTime>, IConvertible, IEquatable<DateTime>, IFormattable
public value class DateTime : IComparable, IComparable<DateTime>, IConvertible, IEquatable<DateTime>, IFormattable, System::Runtime::Serialization::ISerializable
public value class DateTime : IComparable, IComparable<DateTime>, IConvertible, IEquatable<DateTime>, ISpanFormattable, System::Runtime::Serialization::ISerializable
public value class DateTime : IComparable, IComparable<DateTime>, IConvertible, IEquatable<DateTime>, IParsable<DateTime>, ISpanFormattable, ISpanParsable<DateTime>, System::Runtime::Serialization::ISerializable
public value class DateTime : IComparable, IComparable<DateTime>, IConvertible, IEquatable<DateTime>, IParsable<DateTime>, ISpanFormattable, ISpanParsable<DateTime>, IUtf8SpanFormattable, System::Runtime::Serialization::ISerializable
public value class DateTime : IComparable, IConvertible, IFormattable
public value class DateTime : IComparable, IComparable<DateTime>, IEquatable<DateTime>, IFormattable
public struct DateTime : IComparable, IComparable<DateTime>, IConvertible, IEquatable<DateTime>, IFormattable
public readonly struct DateTime : IComparable, IComparable<DateTime>, IConvertible, IEquatable<DateTime>, IFormattable, System.Runtime.Serialization.ISerializable
public readonly struct DateTime : IComparable, IComparable<DateTime>, IConvertible, IEquatable<DateTime>, ISpanFormattable, System.Runtime.Serialization.ISerializable
public readonly struct DateTime : IComparable, IComparable<DateTime>, IConvertible, IEquatable<DateTime>, IParsable<DateTime>, ISpanFormattable, ISpanParsable<DateTime>, System.Runtime.Serialization.ISerializable
public readonly struct DateTime : IComparable, IComparable<DateTime>, IConvertible, IEquatable<DateTime>, IParsable<DateTime>, ISpanFormattable, ISpanParsable<DateTime>, IUtf8SpanFormattable, System.Runtime.Serialization.ISerializable
public struct DateTime : IComparable, IComparable<DateTime>, IConvertible, IEquatable<DateTime>, IFormattable, System.Runtime.Serialization.ISerializable
[System.Serializable]
public struct DateTime : IComparable, IConvertible, IFormattable
[System.Serializable]
public struct DateTime : IComparable, IComparable<DateTime>, IConvertible, IEquatable<DateTime>, IFormattable, System.Runtime.Serialization.ISerializable
public struct DateTime : IComparable, IComparable<DateTime>, IEquatable<DateTime>, IFormattable
type DateTime = struct
interface IConvertible
interface IFormattable
type DateTime = struct
interface IConvertible
interface IFormattable
interface ISerializable
type DateTime = struct
interface IConvertible
interface ISpanFormattable
interface IFormattable
interface ISerializable
type DateTime = struct
interface IConvertible
interface IFormattable
interface IParsable<DateTime>
interface ISpanFormattable
interface ISpanParsable<DateTime>
interface ISerializable
type DateTime = struct
interface IConvertible
interface IFormattable
interface IParsable<DateTime>
interface ISpanFormattable
interface ISpanParsable<DateTime>
interface ISerializable
interface IUtf8SpanFormattable
type DateTime = struct
interface IConvertible
interface IFormattable
interface IParsable<DateTime>
interface ISpanFormattable
interface ISpanParsable<DateTime>
interface IUtf8SpanFormattable
interface ISerializable
[<System.Serializable>]
type DateTime = struct
interface IFormattable
interface IConvertible
[<System.Serializable>]
type DateTime = struct
interface IFormattable
interface IConvertible
interface ISerializable
type DateTime = struct
interface IFormattable
Public Structure DateTime
Implements IComparable, IComparable(Of DateTime), IConvertible, IEquatable(Of DateTime), IFormattable
Public Structure DateTime
Implements IComparable, IComparable(Of DateTime), IConvertible, IEquatable(Of DateTime), IFormattable, ISerializable
Public Structure DateTime
Implements IComparable, IComparable(Of DateTime), IConvertible, IEquatable(Of DateTime), ISerializable, ISpanFormattable
Public Structure DateTime
Implements IComparable, IComparable(Of DateTime), IConvertible, IEquatable(Of DateTime), IParsable(Of DateTime), ISerializable, ISpanFormattable, ISpanParsable(Of DateTime)
Public Structure DateTime
Implements IComparable, IComparable(Of DateTime), IConvertible, IEquatable(Of DateTime), IParsable(Of DateTime), ISerializable, ISpanFormattable, ISpanParsable(Of DateTime), IUtf8SpanFormattable
Public Structure DateTime
Implements IComparable, IConvertible, IFormattable
Public Structure DateTime
Implements IComparable, IComparable(Of DateTime), IEquatable(Of DateTime), IFormattable
- Inheritance
- Attributes
- Implements
For more information about this API, see Supplemental API remarks for DateTime.
Date |
Initializes a new instance of the DateTime structure to the specified DateOnly and TimeOnly and respecting the specified DateTimeKind. |
Date |
Initializes a new instance of the DateTime structure to the specified DateOnly and TimeOnly. The new instance will have the Unspecified kind. |
Date |
Initializes a new instance of the DateTime structure to the specified year, month, and day for the specified calendar. |
Date |
Initializes a new instance of the DateTime structure to the specified year, month, day, hour, minute, and second for the specified calendar. |
Date |
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. |
Date |
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 for the specified calendar. |
Date |
Initializes a new instance of the DateTime structure to the specified year, month, day, hour, minute, second, and millisecond for the specified calendar. |
Date |
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. |
Date |
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 for the specified calendar. |
Date |
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 for the specified calendar. |
Date |
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 for the specified calendar. |
Date |
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 for the specified calendar. |
Date |
Initializes a new instance of the DateTime structure to the specified year, month, day, hour, minute, second, and millisecond. |
Date |
Initializes a new instance of the DateTime structure to the specified year, month, day, hour, minute, and second. |
Date |
Initializes a new instance of the DateTime structure to the specified year, month, and day. |
Date |
Initializes a new instance of the DateTime structure to a specified number of ticks and to Coordinated Universal Time (UTC) or local time. |
Date |
Initializes a new instance of the DateTime structure to a specified number of ticks. |
Max |
Represents the largest possible value of DateTime. This field is read-only. |
Min |
Represents the smallest possible value of DateTime. This field is read-only. |
Unix |
The value of this constant is equivalent to 00:00:00.0000000 UTC, January 1, 1970, in the Gregorian calendar. UnixEpoch defines the point in time when Unix time is equal to 0. |
Date |
Gets the date component of this instance. |
Day |
Gets the day of the month represented by this instance. |
Day |
Gets the day of the week represented by this instance. |
Day |
Gets the day of the year represented by this instance. |
Hour |
Gets the hour component of the date represented by this instance. |
Kind |
Gets a value that indicates whether the time represented by this instance is based on local time, Coordinated Universal Time (UTC), or neither. |
Microsecond |
The microseconds component, expressed as a value between 0 and 999. |
Millisecond |
Gets the milliseconds component of the date represented by this instance. |
Minute |
Gets the minute component of the date represented by this instance. |
Month |
Gets the month component of the date represented by this instance. |
Nanosecond |
The nanoseconds component, expressed as a value between 0 and 900 (in increments of 100 nanoseconds). |
Now |
Gets a DateTime object that is set to the current date and time on this computer, expressed as the local time. |
Second |
Gets the seconds component of the date represented by this instance. |
Ticks |
Gets the number of ticks that represent the date and time of this instance. |
Time |
Gets the time of day for this instance. |
Today |
Gets the current date. |
Utc |
Gets a DateTime object that is set to the current date and time on this computer, expressed as the Coordinated Universal Time (UTC). |
Year |
Gets the year component of the date represented by this instance. |
Add(Time |
Returns a new DateTime that adds the value of the specified TimeSpan to the value of this instance. |
Add |
Returns a new DateTime that adds the specified number of days to the value of this instance. |
Add |
Returns a new DateTime that adds the specified number of hours to the value of this instance. |
Add |
Returns a new DateTime that adds the specified number of microseconds to the value of this instance. |
Add |
Returns a new DateTime that adds the specified number of milliseconds to the value of this instance. |
Add |
Returns a new DateTime that adds the specified number of minutes to the value of this instance. |
Add |
Returns a new DateTime that adds the specified number of months to the value of this instance. |
Add |
Returns a new DateTime that adds the specified number of seconds to the value of this instance. |
Add |
Returns a new DateTime that adds the specified number of ticks to the value of this instance. |
Add |
Returns a new DateTime that adds the specified number of years to the value of this instance. |
Compare(Date |
Compares two instances of DateTime and returns an integer that indicates whether the first instance is earlier than, the same as, or later than the second instance. |
Compare |
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. |
Compare |
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. |
Days |
Returns the number of days in the specified month and year. |
Deconstruct(Date |
Deconstructs this DateTime instance by DateOnly and TimeOnly. |
Deconstruct(Int32, Int32, Int32) |
Deconstructs this DateOnly instance by Year, Month, and Day. |
Equals(Date |
Returns a value indicating whether two DateTime instances have the same date and time value. |
Equals(Date |
Returns a value indicating whether the value of this instance is equal to the value of the specified DateTime instance. |
Equals(Object) |
Returns a value indicating whether this instance is equal to a specified object. |
From |
Deserializes a 64-bit binary value and recreates an original serialized DateTime object. |
From |
Converts the specified Windows file time to an equivalent local time. |
From |
Converts the specified Windows file time to an equivalent UTC time. |
From |
Returns a DateTime equivalent to the specified OLE Automation Date. |
Get |
Converts the value of this instance to all the string representations supported by the standard date and time format specifiers. |
Get |
Converts the value of this instance to all the string representations supported by the specified standard date and time format specifier and culture-specific formatting information. |
Get |
Converts the value of this instance to all the string representations supported by the specified standard date and time format specifier. |
Get |
Converts the value of this instance to all the string representations supported by the standard date and time format specifiers and the specified culture-specific formatting information. |
Get |
Returns the hash code for this instance. |
Get |
|
Is |
Indicates whether this instance of DateTime is within the daylight saving time range for the current time zone. |
Is |
Returns an indication whether the specified year is a leap year. |
Parse(Read |
Converts a memory span that contains string representation of a date and time to its DateTime equivalent by using culture-specific format information and a formatting style. |
Parse(Read |
Parses a span of characters into a value. |
Parse(String, IFormat |
Converts the string representation of a date and time to its DateTime equivalent by using culture-specific format information and a formatting style. |
Parse(String, IFormat |
Converts the string representation of a date and time to its DateTime equivalent by using culture-specific format information. |
Parse(String) |
Converts the string representation of a date and time to its DateTime equivalent by using the conventions of the current culture. |
Parse |
Converts the specified span representation of a date and time to its DateTime equivalent using the specified format, culture-specific format information, and style. The format of the string representation must match the specified format exactly or an exception is thrown. |
Parse |
Converts the specified span representation of a date and time to its DateTime equivalent using the specified array of formats, culture-specific format information, and style. The format of the string representation must match at least one of the specified formats exactly or an exception is thrown. |
Parse |
Converts the specified string representation of a date and time to its DateTime equivalent using the specified format, culture-specific format information, and style. The format of the string representation must match the specified format exactly or an exception is thrown. |
Parse |
Converts the specified string representation of a date and time to its DateTime equivalent using the specified format and culture-specific format information. The format of the string representation must match the specified format exactly. |
Parse |
Converts the specified string representation of a date and time to its DateTime equivalent using the specified array of formats, culture-specific format information, and style. The format of the string representation must match at least one of the specified formats exactly or an exception is thrown. |
Specify |
Creates a new DateTime object that has the same number of ticks as the specified DateTime, but is designated as either local time, Coordinated Universal Time (UTC), or neither, as indicated by the specified DateTimeKind value. |
Subtract(Date |
Returns a new TimeSpan that subtracts the specified date and time from the value of this instance. |
Subtract(Time |
Returns a new DateTime that subtracts the specified duration from the value of this instance. |
To |
Serializes the current DateTime object to a 64-bit binary value that subsequently can be used to recreate the DateTime object. |
To |
Converts the value of the current DateTime object to a Windows file time. |
To |
Converts the value of the current DateTime object to a Windows file time. |
To |
Converts the value of the current DateTime object to local time. |
To |
Converts the value of the current DateTime object to its equivalent long date string representation. |
To |
Converts the value of the current DateTime object to its equivalent long time string representation. |
To |
Converts the value of this instance to the equivalent OLE Automation date. |
To |
Converts the value of the current DateTime object to its equivalent short date string representation. |
To |
Converts the value of the current DateTime object to its equivalent short time string representation. |
To |
Converts the value of the current DateTime object to its equivalent string representation using the formatting conventions of the current culture. |
To |
Converts the value of the current DateTime object to its equivalent string representation using the specified culture-specific format information. |
To |
Converts the value of the current DateTime object to its equivalent string representation using the specified format and culture-specific format information. |
To |
Converts the value of the current DateTime object to its equivalent string representation using the specified format and the formatting conventions of the current culture. |
To |
Converts the value of the current DateTime object to Coordinated Universal Time (UTC). |
Try |
Tries to format the value of the current instance as UTF-8 into the provided span of bytes. |
Try |
Tries to format the value of the current datetime instance into the provided span of characters. |
Try |
Converts the specified char span of a date and time to its DateTime equivalent and returns a value that indicates whether the conversion succeeded. |
Try |
Tries to parse a span of characters into a value. |
Try |
Converts the span representation of a date and time to its DateTime equivalent using the specified culture-specific format information and formatting style, and returns a value that indicates whether the conversion succeeded. |
Try |
Converts the specified string representation of a date and time to its DateTime equivalent and returns a value that indicates whether the conversion succeeded. |
Try |
Tries to parse a string into a value. |
Try |
Converts the specified string representation of a date and time to its DateTime equivalent using the specified culture-specific format information and formatting style, and returns a value that indicates whether the conversion succeeded. |
Try |
Converts the specified span representation of a date and time to its DateTime equivalent using the specified format, culture-specific format information, and style. The format of the string representation must match the specified format exactly. The method returns a value that indicates whether the conversion succeeded. |
Try |
Converts the specified char span of a date and time to its DateTime equivalent and returns a value that indicates whether the conversion succeeded. |
Try |
Converts the specified string representation of a date and time to its DateTime equivalent using the specified format, culture-specific format information, and style. The format of the string representation must match the specified format exactly. The method returns a value that indicates whether the conversion succeeded. |
Try |
Converts the specified string representation of a date and time to its DateTime equivalent using the specified array of formats, culture-specific format information, and style. The format of the string representation must match at least one of the specified formats exactly. The method returns a value that indicates whether the conversion succeeded. |
Addition(Date |
Adds a specified time interval to a specified date and time, yielding a new date and time. |
Equality(Date |
Determines whether two specified instances of DateTime are equal. |
Greater |
Determines whether one specified DateTime is later than another specified DateTime. |
Greater |
Determines whether one specified DateTime represents a date and time that is the same as or later than another specified DateTime. |
Inequality(Date |
Determines whether two specified instances of DateTime are not equal. |
Less |
Determines whether one specified DateTime is earlier than another specified DateTime. |
Less |
Determines whether one specified DateTime represents a date and time that is the same as or earlier than another specified DateTime. |
Subtraction(Date |
Subtracts a specified date and time from another specified date and time and returns a time interval. |
Subtraction(Date |
Subtracts a specified time interval from a specified date and time and returns a new date and time. |
IComparable. |
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object. |
IConvertible. |
Returns the TypeCode for this instance. |
IConvertible. |
This conversion is not supported. Attempting to use this method throws an InvalidCastException. |
IConvertible. |
This conversion is not supported. Attempting to use this method throws an InvalidCastException. |
IConvertible. |
This conversion is not supported. Attempting to use this method throws an InvalidCastException. |
IConvertible. |
Returns the current DateTime object. |
IConvertible. |
This conversion is not supported. Attempting to use this method throws an InvalidCastException. |
IConvertible. |
This conversion is not supported. Attempting to use this method throws an InvalidCastException. |
IConvertible. |
This conversion is not supported. Attempting to use this method throws an InvalidCastException. |
IConvertible. |
This conversion is not supported. Attempting to use this method throws an InvalidCastException. |
IConvertible. |
This conversion is not supported. Attempting to use this method throws an InvalidCastException. |
IConvertible. |
This conversion is not supported. Attempting to use this method throws an InvalidCastException. |
IConvertible. |
This conversion is not supported. Attempting to use this method throws an InvalidCastException. |
IConvertible. |
Converts the current DateTime object to an object of a specified type. |
IConvertible. |
This conversion is not supported. Attempting to use this method throws an InvalidCastException. |
IConvertible. |
This conversion is not supported. Attempting to use this method throws an InvalidCastException. |
IConvertible. |
This conversion is not supported. Attempting to use this method throws an InvalidCastException. |
ISerializable. |
Populates a SerializationInfo object with the data needed to serialize the current DateTime object. |
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
All members of this type are thread safe. Members that appear to modify instance state actually return a new instance initialized with the new value. As with any other type, reading and writing to a shared variable that contains an instance of this type must be protected by a lock to guarantee thread safety.
.NET feedback
.NET is an open source project. Select a link to provide feedback: