Skip to main content
.NET Framework Class Library
DateTime Structure

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

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)
Syntax
<[%$TOPIC/03ybds8y_en-us_VS_110_1_0_0_0_0%]> _
Public Structure DateTime _
	Implements [%$TOPIC/03ybds8y_en-us_VS_110_1_0_0_0_1%], [%$TOPIC/03ybds8y_en-us_VS_110_1_0_0_0_2%], [%$TOPIC/03ybds8y_en-us_VS_110_1_0_0_0_3%], [%$TOPIC/03ybds8y_en-us_VS_110_1_0_0_0_4%],  _
	[%$TOPIC/03ybds8y_en-us_VS_110_1_0_0_0_5%](Of DateTime), [%$TOPIC/03ybds8y_en-us_VS_110_1_0_0_0_6%](Of DateTime)
[[%$TOPIC/03ybds8y_en-us_VS_110_1_0_1_0_0%]]
public struct DateTime : [%$TOPIC/03ybds8y_en-us_VS_110_1_0_1_0_1%], [%$TOPIC/03ybds8y_en-us_VS_110_1_0_1_0_2%], 
	[%$TOPIC/03ybds8y_en-us_VS_110_1_0_1_0_3%], [%$TOPIC/03ybds8y_en-us_VS_110_1_0_1_0_4%], [%$TOPIC/03ybds8y_en-us_VS_110_1_0_1_0_5%]<DateTime>, [%$TOPIC/03ybds8y_en-us_VS_110_1_0_1_0_6%]<DateTime>
[[%$TOPIC/03ybds8y_en-us_VS_110_1_0_2_0_0%]]
public value class DateTime : [%$TOPIC/03ybds8y_en-us_VS_110_1_0_2_0_1%], 
	[%$TOPIC/03ybds8y_en-us_VS_110_1_0_2_0_2%], [%$TOPIC/03ybds8y_en-us_VS_110_1_0_2_0_3%], [%$TOPIC/03ybds8y_en-us_VS_110_1_0_2_0_4%], [%$TOPIC/03ybds8y_en-us_VS_110_1_0_2_0_5%]<DateTime>, 
	[%$TOPIC/03ybds8y_en-us_VS_110_1_0_2_0_6%]<DateTime>
[<[%$TOPIC/03ybds8y_en-us_VS_110_1_0_3_0_0%]>]
[<[%$TOPIC/03ybds8y_en-us_VS_110_1_0_3_0_1%]>]
type DateTime =  
    struct 
        interface [%$TOPIC/03ybds8y_en-us_VS_110_1_0_3_0_2%] 
        interface [%$TOPIC/03ybds8y_en-us_VS_110_1_0_3_0_3%] 
        interface [%$TOPIC/03ybds8y_en-us_VS_110_1_0_3_0_4%] 
        interface [%$TOPIC/03ybds8y_en-us_VS_110_1_0_3_0_5%] 
        interface [%$TOPIC/03ybds8y_en-us_VS_110_1_0_3_0_6%]<DateTime>
        interface [%$TOPIC/03ybds8y_en-us_VS_110_1_0_3_0_7%]<DateTime>
    end

The DateTime type exposes the following members.

Constructors
  NameDescription
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps DateTime(Int64)Initializes a new instance of the DateTime structure to a specified number of ticks.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps DateTime(Int64, DateTimeKind)Initializes a new instance of the DateTime structure to a specified number of ticks and to Coordinated Universal Time (UTC) or local time.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps DateTime(Int32, Int32, Int32)Initializes a new instance of the DateTime structure to the specified year, month, and day.
Public method Supported by the XNA Framework DateTime(Int32, Int32, Int32, Calendar)Initializes a new instance of the DateTime structure to the specified year, month, and day for the specified calendar.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps DateTime(Int32, Int32, Int32, Int32, Int32, Int32)Initializes a new instance of the DateTime structure to the specified year, month, day, hour, minute, and second.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps DateTime(Int32, Int32, Int32, Int32, Int32, Int32, DateTimeKind)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.
Public method Supported by the XNA Framework DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Calendar)Initializes a new instance of the DateTime structure to the specified year, month, day, hour, minute, and second for the specified calendar.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32)Initializes a new instance of the DateTime structure to the specified year, month, day, hour, minute, second, and millisecond.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, DateTimeKind)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.
Public method Supported by the XNA Framework DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar)Initializes a new instance of the DateTime structure to the specified year, month, day, hour, minute, second, and millisecond for the specified calendar.
Public method Supported by the XNA Framework DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Calendar, DateTimeKind)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.
Top
Properties
  NameDescription
Public property Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps DateGets the date component of this instance.
Public property Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps DayGets the day of the month represented by this instance.
Public property Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps DayOfWeekGets the day of the week represented by this instance.
Public property Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps DayOfYearGets the day of the year represented by this instance.
Public property Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps HourGets the hour component of the date represented by this instance.
Public property Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps KindGets a value that indicates whether the time represented by this instance is based on local time, Coordinated Universal Time (UTC), or neither.
Public property Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps MillisecondGets the milliseconds component of the date represented by this instance.
Public property Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps MinuteGets the minute component of the date represented by this instance.
Public property Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps MonthGets the month component of the date represented by this instance.
Public property Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps NowGets a DateTime object that is set to the current date and time on this computer, expressed as the local time.
Public property Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps SecondGets the seconds component of the date represented by this instance.
Public property Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps TicksGets the number of ticks that represent the date and time of this instance.
Public property Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps TimeOfDayGets the time of day for this instance.
Public property Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps TodayGets the current date.
Public property Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps UtcNowGets a DateTime object that is set to the current date and time on this computer, expressed as the Coordinated Universal Time (UTC).
Public property Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps YearGets the year component of the date represented by this instance.
Top
Methods
  NameDescription
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps AddReturns a new DateTime that adds the value of the specified TimeSpan to the value of this instance.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps AddDaysReturns a new DateTime that adds the specified number of days to the value of this instance.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps AddHoursReturns a new DateTime that adds the specified number of hours to the value of this instance.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps AddMillisecondsReturns a new DateTime that adds the specified number of milliseconds to the value of this instance.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps AddMinutesReturns a new DateTime that adds the specified number of minutes to the value of this instance.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps AddMonthsReturns a new DateTime that adds the specified number of months to the value of this instance.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps AddSecondsReturns a new DateTime that adds the specified number of seconds to the value of this instance.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps AddTicksReturns a new DateTime that adds the specified number of ticks to the value of this instance.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps AddYearsReturns a new DateTime that adds the specified number of years to the value of this instance.
Public method Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps CompareCompares 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.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps CompareTo(DateTime)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.
Public method Supported by the XNA Framework CompareTo(Object)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.
Public method Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps DaysInMonthReturns the number of days in the specified month and year.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps Equals(DateTime)Returns a value indicating whether the value of this instance is equal to the value of the specified DateTime instance.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps Equals(Object)Returns a value indicating whether this instance is equal to a specified object. (Overrides ValueTypeEquals(Object).)
Public method Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps Equals(DateTime, DateTime)Returns a value indicating whether two DateTime instances have the same date and time value.
Public method Static member Supported by Portable Class Library Supported in .NET for Windows Store apps FromBinaryDeserializes a 64-bit binary value and recreates an original serialized DateTime object.
Public method Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps FromFileTimeConverts the specified Windows file time to an equivalent local time.
Public method Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps FromFileTimeUtcConverts the specified Windows file time to an equivalent UTC time.
Public method Static member Supported by the XNA Framework FromOADateReturns a DateTime equivalent to the specified OLE Automation Date.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps GetDateTimeFormatsConverts the value of this instance to all the string representations supported by the standard date and time format specifiers.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps GetDateTimeFormats(Char)Converts the value of this instance to all the string representations supported by the specified standard date and time format specifier.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps GetDateTimeFormats(IFormatProvider)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.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps GetDateTimeFormats(Char, IFormatProvider)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.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps GetHashCodeReturns the hash code for this instance. (Overrides ValueTypeGetHashCode.)
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps GetTypeGets the Type of the current instance. (Inherited from Object.)
Public method Supported by the XNA Framework GetTypeCodeReturns the TypeCode for value type DateTime.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps IsDaylightSavingTimeIndicates whether this instance of DateTime is within the daylight saving time range for the current time zone.
Public method Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps IsLeapYearReturns an indication whether the specified year is a leap year.
Public method Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps Parse(String)Converts the string representation of a date and time to its DateTime equivalent.
Public method Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps Parse(String, IFormatProvider)Converts the string representation of a date and time to its DateTime equivalent by using culture-specific format information.
Public method Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps Parse(String, IFormatProvider, DateTimeStyles)Converts the string representation of a date and time to its DateTime equivalent by using culture-specific format information and formatting style.
Public method Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps ParseExact(String, String, IFormatProvider)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.
Public method Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps ParseExact(String, String, IFormatProvider, DateTimeStyles)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.
Public method Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps ParseExact(String, String, IFormatProvider, DateTimeStyles)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.
Public method Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps SpecifyKindCreates 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.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps Subtract(DateTime)Subtracts the specified date and time from this instance.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps Subtract(TimeSpan)Subtracts the specified duration from this instance.
Public method Supported by Portable Class Library Supported in .NET for Windows Store apps ToBinarySerializes the current DateTime object to a 64-bit binary value that subsequently can be used to recreate the DateTime object.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps ToFileTimeConverts the value of the current DateTime object to a Windows file time.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps ToFileTimeUtcConverts the value of the current DateTime object to a Windows file time.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps ToLocalTimeConverts the value of the current DateTime object to local time.
Public method Supported by the XNA Framework ToLongDateStringConverts the value of the current DateTime object to its equivalent long date string representation.
Public method Supported by the XNA Framework ToLongTimeStringConverts the value of the current DateTime object to its equivalent long time string representation.
Public method Supported by the XNA Framework ToOADateConverts the value of this instance to the equivalent OLE Automation date.
Public method Supported by the XNA Framework ToShortDateStringConverts the value of the current DateTime object to its equivalent short date string representation.
Public method Supported by the XNA Framework ToShortTimeStringConverts the value of the current DateTime object to its equivalent short time string representation.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps ToStringConverts the value of the current DateTime object to its equivalent string representation. (Overrides ValueTypeToString.)
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps ToString(IFormatProvider)Converts the value of the current DateTime object to its equivalent string representation using the specified culture-specific format information.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps ToString(String)Converts the value of the current DateTime object to its equivalent string representation using the specified format.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps ToString(String, IFormatProvider)Converts the value of the current DateTime object to its equivalent string representation using the specified format and culture-specific format information.
Public method Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps ToUniversalTimeConverts the value of the current DateTime object to Coordinated Universal Time (UTC).
Public method Static member Supported by Portable Class Library Supported in .NET for Windows Store apps TryParse(String, DateTime)Converts the specified string representation of a date and time to its DateTime equivalent and returns a value that indicates whether the conversion succeeded.
Public method Static member Supported by Portable Class Library Supported in .NET for Windows Store apps TryParse(String, IFormatProvider, DateTimeStyles, DateTime)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.
Public method Static member Supported by Portable Class Library Supported in .NET for Windows Store apps TryParseExact(String, String, IFormatProvider, DateTimeStyles, DateTime)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.
Public method Static member Supported by Portable Class Library Supported in .NET for Windows Store apps TryParseExact(String, String, IFormatProvider, DateTimeStyles, DateTime)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.
Top
Operators
  NameDescription
Public operator Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps AdditionAdds a specified time interval to a specified date and time, yielding a new date and time.
Public operator Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps EqualityDetermines whether two specified instances of DateTime are equal.
Public operator Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps GreaterThanDetermines whether one specified DateTime is greater than another specified DateTime.
Public operator Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps GreaterThanOrEqualDetermines whether one specified DateTime is greater than or equal to another specified DateTime.
Public operator Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps InequalityDetermines whether two specified instances of DateTime are not equal.
Public operator Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps LessThanDetermines whether one specified DateTime is less than another specified DateTime.
Public operator Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps LessThanOrEqualDetermines whether one specified DateTime is less than or equal to another specified DateTime.
Public operator Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps Subtraction(DateTime, DateTime)Subtracts a specified date and time from another specified date and time and returns a time interval.
Public operator Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps Subtraction(DateTime, TimeSpan)Subtracts a specified time interval from a specified date and time and returns a new date and time.
Top
Fields
  NameDescription
Public field Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps MaxValueRepresents the largest possible value of DateTime. This field is read-only.
Public field Static member Supported by the XNA Framework Supported by Portable Class Library Supported in .NET for Windows Store apps MinValueRepresents the smallest possible value of DateTime. This field is read-only.
Top
Explicit Interface Implementations
  NameDescription
Explicit interface implemetation Private method Supported by Portable Class Library Supported in .NET for Windows Store apps IComparableCompareToCompares the current instance with another object of the same type and returns an integer that indicates whether this instance precedes, follows, or occurs in the same position in the sort order as the other object.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToBooleanInfrastructure. This conversion is not supported. Attempting to use this method throws an InvalidCastException.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToByteInfrastructure. This conversion is not supported. Attempting to use this method throws an InvalidCastException.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToCharInfrastructure. This conversion is not supported. Attempting to use this method throws an InvalidCastException.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToDateTimeInfrastructure. Returns the current DateTime object.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToDecimalInfrastructure. This conversion is not supported. Attempting to use this method throws an InvalidCastException.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToDoubleInfrastructure. This conversion is not supported. Attempting to use this method throws an InvalidCastException.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToInt16Infrastructure. This conversion is not supported. Attempting to use this method throws an InvalidCastException.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToInt32Infrastructure. This conversion is not supported. Attempting to use this method throws an InvalidCastException.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToInt64Infrastructure. This conversion is not supported. Attempting to use this method throws an InvalidCastException.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToSByteInfrastructure. This conversion is not supported. Attempting to use this method throws an InvalidCastException.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToSingleInfrastructure. This conversion is not supported. Attempting to use this method throws an InvalidCastException.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToTypeInfrastructure. Converts the current DateTime object to an object of a specified type.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToUInt16Infrastructure. This conversion is not supported. Attempting to use this method throws an InvalidCastException.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToUInt32Infrastructure. This conversion is not supported. Attempting to use this method throws an InvalidCastException.
Explicit interface implemetation Private method Supported by the XNA Framework IConvertibleToUInt64Infrastructure. This conversion is not supported. Attempting to use this method throws an InvalidCastException.
Explicit interface implemetation Private method ISerializableGetObjectDataPopulates a SerializationInfo object with the data needed to serialize the current DateTime object.
Top
Remarks

The DateTime value type represents dates and times with values ranging from 00:00:00 (midnight), January 1, 0001 Anno Domini (Common Era) through 11:59:59 P.M., December 31, 9999 A.D. (C.E.) in the Gregorian calendar.

Time values are measured in 100-nanosecond units called ticks, and a particular date is the number of ticks since 12:00 midnight, January 1, 0001 A.D. (C.E.) in the GregorianCalendar calendar (excluding ticks that would be added by leap seconds). For example, a ticks value of 31241376000000000L represents the date, Friday, January 01, 0100 12:00:00 midnight. A DateTime value is always expressed in the context of an explicit or default calendar.

NoteNote

If you are working with a ticks value that you want to convert to some other time interval, such as minutes or seconds, you should use the TimeSpanTicksPerDay, TimeSpanTicksPerHour, TimeSpanTicksPerMinute, TimeSpanTicksPerSecond, or TimeSpanTicksPerMillisecond constant to perform the conversion. For example, to add the number of seconds represented by a specified number of ticks to the Second component of a DateTime value, you can use the expression dateValue.Second + nTicks/Timespan.TicksPerSecond.

In this section:

Instantiating a DateTime object
DateTime values and their string representations
Version considerations
DateTime values
DateTime operations
DateTime vs. TimeSpan
COM interop considerations

Instantiating a DateTime object

You can create a new DateTime value in any of the following ways:

  • By calling any of the overloads of the DateTime constructor that allow you to specify specific elements of the date and time value (such as the year, month, and day, or the number of ticks). The following statement illustrates a call to one of the DateTime constructors to create a date with a specific year, month, day, hour, minute, and second.

    Dim date1 As New Date(2008, 5, 1, 8, 30, 52)
    DateTime date1 = new DateTime(2008, 5, 1, 8, 30, 52);
  • By using any compiler-specific syntax for declaring date and time values. For example, the following Visual Basic statement initializes a new DateTime value.

    Dim date1 As Date = #5/1/2008 8:30:52AM#
  • By assigning the DateTime object a date and time value returned by a property or method. The following example assigns the current date and time, the current Coordinated Universal Time (UTC) date and time, and the current date to three new DateTime variables.

    Dim date1 As Date = Date.Now
    Dim date2 As Date = Date.UtcNow
    Dim date3 As Date = Date.Today
    DateTime date1 = DateTime.Now;
    DateTime date2 = DateTime.UtcNow;
    DateTime date3 = DateTime.Today;
  • By parsing the string representation of a date and time value. The Parse, ParseExact, TryParse, and TryParseExact methods all convert a string to its equivalent date and time value. The following example uses the Parse method to parse a string and convert it to a DateTime value.

    Dim dateString As String = "5/1/2008 8:30:52 AM" 
    Dim date1 As Date = Date.Parse(dateString, _
                             System.Globalization.CultureInfo.InvariantCulture) 
    string dateString = "5/1/2008 8:30:52 AM";
    DateTime date1 = DateTime.Parse(dateString, 
                              System.Globalization.CultureInfo.InvariantCulture); 

    Note that the TryParse and TryParseExact methods indicate whether a particular string contains a valid representation of a DateTime value in addition to performing the conversion.

  • By calling the DateTime structure's implicit default constructor. (For details on the implicit default constructor of a value type, see Value Types (C# Reference).) An approximate equivalent, for compilers that support it, is declaring a DateTime value without explicitly assigning a date and time to it. The following example illustrates a call to the DateTime implicit default constructor in C# and Visual Basic, as well as a DateTime variable declaration with no assignment in Visual Basic.

    Dim dat1 As DateTime
    ' The following method call displays 1/1/0001 12:00:00 AM.
    Console.WriteLine(dat1.ToString(System.Globalization.CultureInfo.InvariantCulture))
    ' The following method call displays True.
    Console.WriteLine(dat1.Equals(Date.MinValue))
    
    Dim dat2 As New DateTime()
    ' The following method call displays 1/1/0001 12:00:00 AM.
    Console.WriteLine(dat2.ToString(System.Globalization.CultureInfo.InvariantCulture))
    ' The following method call displays True.
    Console.WriteLine(dat2.Equals(Date.MinValue))
    DateTime dat1 = new DateTime();
    // The following method call displays 1/1/0001 12:00:00 AM.
    Console.WriteLine(dat1.ToString(System.Globalization.CultureInfo.InvariantCulture));
    // The following method call displays True.
    Console.WriteLine(dat1.Equals(DateTime.MinValue));

DateTime Values and their string representations

Internally, all DateTime values are represented as the number of ticks (the number of 100-nanosecond intervals) that have elapsed since 12:00:00 midnight, January 1, 0001. The actual DateTime value is independent of the way in which that value appears when displayed in a user interface element or when written to a file. The appearance of a DateTime value is the result of a formatting operation. Formatting is the process of converting a value to its string representation.

Because the appearance of date and time values is dependent on such factors as culture, international standards, application requirements, and personal preference, the DateTime structure offers a great deal of flexibility in formatting date and time values through the overloads of its ToString method. The default DateTimeToString method returns the string representation of a date and time value using the current culture's short date and long time pattern. The following example uses the default DateTimeToString method to display the date and time using the short date and long time pattern for the en-US culture, the current culture on the computer on which the example was run.

Dim date1 As Date = #3/1/2008 7:00AM#
Console.WriteLine(date1.ToString())
' For en-US culture, displays 3/1/2008 7:00:00 AM
DateTime date1 = new DateTime(2008, 3, 1, 7, 0, 0);
Console.WriteLine(date1.ToString());
// For en-US culture, displays 3/1/2008 7:00:00 AM

The DateTimeToString(IFormatProvider) method returns the string representation of a date and time value using the short date and long time pattern of a specific culture. The following example uses the DateTimeToString(IFormatProvider) method to display the date and time using the short date and long time pattern for the fr-FR culture.

Dim date1 As Date = #3/1/2008 7:00AM#
Console.WriteLine(date1.ToString(System.Globalization.CultureInfo.CreateSpecificCulture("fr-FR")))
' Displays 01/03/2008 07:00:00
DateTime date1 = new DateTime(2008, 3, 1, 7, 0, 0);
Console.WriteLine(date1.ToString(System.Globalization.CultureInfo.CreateSpecificCulture("fr-FR")));
// Displays 01/03/2008 07:00:00

The DateTimeToString(String) method returns the string representation of the date and time in a format defined by a standard or custom format specifier and using the formatting conventions of the current culture. The following example uses the DateTimeToString(String) method to display the full date and time pattern for the en-US culture, the current culture on the computer on which the example was run.

Dim date1 As Date = #3/1/2008 7:00AM#
Console.WriteLine(date1.ToString("F"))
' Displays Saturday, March 01, 2008 7:00:00 AM
DateTime date1 = new DateTime(2008, 3, 1, 7, 0, 0);
Console.WriteLine(date1.ToString("F"));
// Displays Saturday, March 01, 2008 7:00:00 AM

The DateTimeToString(String, IFormatProvider) method returns the string representation of the date and time in a format defined by a specific format specifier and using the formatting conventions of a specific culture. The following example uses the DateTimeToString(String, IFormatProvider) method to display the full date and time pattern for the fr-FR culture.

Dim date1 As Date = #3/1/2008 7:00AM#
Console.WriteLine(date1.ToString("F", New System.Globalization.CultureInfo("fr-FR")))
' Displays samedi 1 mars 2008 07:00:00
DateTime date1 = new DateTime(2008, 3, 1, 7, 0, 0);
Console.WriteLine(date1.ToString("F", new System.Globalization.CultureInfo("fr-FR")));
// Displays samedi 1 mars 2008 07:00:00

Version considerations

Prior to the .NET Framework version 2.0, the DateTime structure contains a 64-bit field composed of an unused 2-bit field concatenated with a private Ticks field, which is a 62-bit unsigned field that contains the number of ticks that represent the date and time. The value of the Ticks field can be obtained with the Ticks property.

Starting with the .NET Framework 2.0, the DateTime structure contains a 64-bit field composed of a private Kind field concatenated with the Ticks field. The Kind field is a 2-bit field that indicates whether the DateTime structure represents a local time, a Coordinated Universal Time (UTC), or the time in an unspecified time zone. The Kind field is used when performing time conversions between time zones, but not for time comparisons or arithmetic. The value of the Kind field can be obtained with the Kind property.

NoteNote

An alternative to the DateTime structure for working with date and time values in particular time zones is the DateTimeOffset structure. The DateTimeOffset structure stores date and time information in a private DateTime field and the number of minutes by which that date and time differs from UTC in a private Int16 field. This makes it possible for a DateTimeOffset value to reflect the time in a particular time zone, whereas a DateTime value can unambiguously reflect only UTC and the local time zone's time. For a discussion about when to use the DateTime structure or the DateTimeOffset structure when working with date and time values, see Choosing Between DateTime, DateTimeOffset, and TimeZoneInfo.

DateTime values

Descriptions of time values in the DateTime type are often expressed using the Coordinated Universal Time (UTC) standard, which is the internationally recognized name for Greenwich Mean Time (GMT). Coordinated Universal Time is the time as measured at zero degrees longitude, the UTC origin point. Daylight saving time is not applicable to UTC.

Local time is relative to a particular time zone. A time zone is associated with a time zone offset, which is the displacement of the time zone measured in hours from the UTC origin point. In addition, local time is optionally affected by daylight saving time, which adds or subtracts an hour from the length of a day. Consequently, local time is calculated by adding the time zone offset to UTC and adjusting for daylight saving time if necessary. The time zone offset at the UTC origin point is zero.

UTC time is suitable for calculations, comparisons, and storing dates and time in files. Local time is appropriate for display in user interfaces of desktop applications. Time zone-aware applications (such as many Web applications) also need to work with a number of other time zones.

If the Kind property of a DateTime object is DateTimeKindUnspecified, it is unspecified whether the time represented is local time, UTC time, or a time in some other time zone.

DateTime operations

A calculation using a DateTime structure, such as Add or Subtract, does not modify the value of the structure. Instead, the calculation returns a new DateTime structure whose value is the result of the calculation.

Conversion operations between time zones (such as between UTC and local time, or between one time zone and another) take daylight saving time into account, but arithmetic and comparison operations do not.

The DateTime structure itself offers limited support for converting from one time zone to another. You can use the ToLocalTime method to convert UTC to local time, or you can use the ToUniversalTime method to convert from local time to UTC. However, a full set of time zone conversion methods is available in the TimeZoneInfo class. Using these methods, you can convert the time in any one of the world's time zones to the time in any other time zone.

Calculations and comparisons of DateTime objects are meaningful only if the objects represent times in the same time zone. You can use a TimeZoneInfo object to represent a DateTime value's time zone, although the two are loosely coupled. (That is, a DateTime object does not have a property that returns an object that represents that date and time value's time zone other than the Kind property.) For this reason, in a time zone-aware application, you must rely on some external mechanism to determine the time zone in which a DateTime object was created. For example, you could use a structure that wraps both the DateTime value and the TimeZoneInfo object that represents the DateTime value's time zone. For details on using UTC in calculations and comparisons with DateTime values, see Performing Arithmetic Operations with Dates and Times.

Each DateTime member implicitly uses the Gregorian calendar to perform its operation, with the exception of constructors that specify a calendar, and methods with a parameter derived from IFormatProvider, such as System.GlobalizationDateTimeFormatInfo, that implicitly specifies a calendar.

Operations by members of the DateTime type take into account details such as leap years and the number of days in a month.

DateTime vs. TimeSpan

The DateTime and TimeSpan value types differ in that a DateTime represents an instant in time whereas a TimeSpan represents a time interval. This means, for example, that you can subtract one instance of DateTime from another to obtain a TimeSpan object that represents the time interval between them. Or you could add a positive TimeSpan to the current DateTime to obtain a DateTime value that represents a future date.

You can add or subtract a time interval from a DateTime object. Time intervals can be negative or positive, can be expressed in units such as ticks or seconds, or can be expressed as a TimeSpan object.

COM interop considerations

A DateTime value that is transferred to a COM application, then is transferred back to a managed application, is said to round-trip. However, a DateTime value that specifies only a time does not round-trip as you might expect.

If you round-trip only a time, such as 3 P.M., the final date and time is December 30, 1899 C.E. at 3:00 P.M., instead of January, 1, 0001 C.E. at 3:00 P.M. This happens because the .NET Framework and COM assume a default date when only a time is specified. However, the COM system assumes a base date of December 30, 1899 C.E. while the .NET Framework assumes a base date of January, 1, 0001 C.E.

When only a time is passed from the .NET Framework to COM, special processing is performed that converts the time to the format used by COM. When only a time is passed from COM to the .NET Framework, no special processing is performed because that would corrupt legitimate dates and times on or before December 30, 1899. This also means if a date starts its round-trip from COM, the .NET Framework and COM preserve the date.

The behavior of the .NET Framework and COM means that if your application round-trips a DateTime that only specifies a time, your application must remember to modify or ignore the erroneous date from the final DateTime object.

Examples

The following example demonstrates how to compare roughly equivalent DateTime values, accepting a small margin of difference when declaring them equal.

Class DateTimeTester
   Shared Function RoughlyEquals(time As DateTime, timeWithWindow As DateTime, _
                                 windowInSeconds As Integer, _
                                 frequencyInSeconds As Integer) As Boolean 
      Dim delta As Long = (timeWithWindow.Subtract(time)).TotalSeconds _
                                                Mod frequencyInSeconds

      If delta > windowInSeconds Then 
         delta = frequencyInSeconds - delta 
      End If 

      Return Math.Abs(delta) < windowInSeconds
   End Function 

   Public Shared Sub Main()
      Dim window As Integer = 10
      Dim freq As Integer = 60 * 60 * 2 ' 2 hours;
      Dim d1 As DateTime = DateTime.Now

      Dim d2 As DateTime = d1.AddSeconds((2 * window))
      Dim d3 As DateTime = d1.AddSeconds((- 2 * window))
      Dim d4 As DateTime = d1.AddSeconds((window / 2))
      Dim d5 As DateTime = d1.AddSeconds((- window / 2))

      Dim d6 As DateTime = d1.AddHours(2).AddSeconds((2 * window))
      Dim d7 As DateTime = d1.AddHours(2).AddSeconds((- 2 * window))
      Dim d8 As DateTime = d1.AddHours(2).AddSeconds((window / 2))
      Dim d9 As DateTime = d1.AddHours(2).AddSeconds((- window / 2))

      Console.WriteLine("d1 ({0}) ~= d1 ({1}): {2}", _
                        d1, d1, RoughlyEquals(d1, d1, window, freq))
      Console.WriteLine("d1 ({0}) ~= d2 ({1}): {2}", _
                        d1, d2, RoughlyEquals(d1, d2, window, freq))
      Console.WriteLine("d1 ({0}) ~= d3 ({1}): {2}", _
                        d1, d3, RoughlyEquals(d1, d3, window, freq))
      Console.WriteLine("d1 ({0}) ~= d4 ({1}): {2}", _
                        d1, d4, RoughlyEquals(d1, d4, window, freq))
      Console.WriteLine("d1 ({0}) ~= d5 ({1}): {2}", _
                        d1, d5, RoughlyEquals(d1, d5, window, freq))

      Console.WriteLine("d1 ({0}) ~= d6 ({1}): {2}", _
                        d1, d6, RoughlyEquals(d1, d6, window, freq))
      Console.WriteLine("d1 ({0}) ~= d7 ({1}): {2}", _
                        d1, d7, RoughlyEquals(d1, d7, window, freq))
      Console.WriteLine("d1 ({0}) ~= d8 ({1}): {2}", _
                        d1, d8, RoughlyEquals(d1, d8, window, freq))
      Console.WriteLine("d1 ({0}) ~= d9 ({1}): {2}", _
                        d1, d9, RoughlyEquals(d1, d9, window, freq))
   End Sub 
End Class 
' The example displays output similar to the following: 
'    d1 (1/28/2010 9:01:26 PM) ~= d1 (1/28/2010 9:01:26 PM): True 
'    d1 (1/28/2010 9:01:26 PM) ~= d2 (1/28/2010 9:01:46 PM): False 
'    d1 (1/28/2010 9:01:26 PM) ~= d3 (1/28/2010 9:01:06 PM): False 
'    d1 (1/28/2010 9:01:26 PM) ~= d4 (1/28/2010 9:01:31 PM): True 
'    d1 (1/28/2010 9:01:26 PM) ~= d5 (1/28/2010 9:01:21 PM): True 
'    d1 (1/28/2010 9:01:26 PM) ~= d6 (1/28/2010 11:01:46 PM): False 
'    d1 (1/28/2010 9:01:26 PM) ~= d7 (1/28/2010 11:01:06 PM): False 
'    d1 (1/28/2010 9:01:26 PM) ~= d8 (1/28/2010 11:01:31 PM): True 
'    d1 (1/28/2010 9:01:26 PM) ~= d9 (1/28/2010 11:01:21 PM): True
using System;

class DateTimeTester 
{
   static bool RoughlyEquals(DateTime time, DateTime timeWithWindow, int windowInSeconds, int frequencyInSeconds)
   {
      long delta = (long)((TimeSpan)(timeWithWindow - time)).TotalSeconds 
                                                     % frequencyInSeconds;

      delta = delta > windowInSeconds ? frequencyInSeconds - delta : delta;

      return Math.Abs(delta) < windowInSeconds;
	}

	public static void Main() 
	{
      int window = 10;
      int freq = 60 * 60 * 2; // 2 hours;

      DateTime d1 = DateTime.Now;

      DateTime d2 = d1.AddSeconds(2 * window);
      DateTime d3 = d1.AddSeconds(-2 * window);
      DateTime d4 = d1.AddSeconds(window / 2);
      DateTime d5 = d1.AddSeconds(-window / 2);

      DateTime d6 = (d1.AddHours(2)).AddSeconds(2 * window);
      DateTime d7 = (d1.AddHours(2)).AddSeconds(-2 * window);
      DateTime d8 = (d1.AddHours(2)).AddSeconds(window / 2);
      DateTime d9 = (d1.AddHours(2)).AddSeconds(-window / 2);

      Console.WriteLine("d1 ({0}) ~= d1 ({1}): {2}",
                        d1, d1, RoughlyEquals(d1, d1, window, freq));
      Console.WriteLine("d1 ({0}) ~= d2 ({1}): {2}", 
                        d1, d2, RoughlyEquals(d1, d2, window, freq));
      Console.WriteLine("d1 ({0}) ~= d3 ({1}): {2}", 
                        d1, d3, RoughlyEquals(d1, d3, window, freq));
      Console.WriteLine("d1 ({0}) ~= d4 ({1}): {2}", 
                        d1, d4, RoughlyEquals(d1, d4, window, freq));
      Console.WriteLine("d1 ({0}) ~= d5 ({1}): {2}", 
                        d1, d5, RoughlyEquals(d1, d5, window, freq));

      Console.WriteLine("d1 ({0}) ~= d6 ({1}): {2}", 
                        d1, d6, RoughlyEquals(d1, d6, window, freq));
      Console.WriteLine("d1 ({0}) ~= d7 ({1}): {2}", 
                        d1, d7, RoughlyEquals(d1, d7, window, freq));
      Console.WriteLine("d1 ({0}) ~= d8 ({1}): {2}", 
                        d1, d8, RoughlyEquals(d1, d8, window, freq));
      Console.WriteLine("d1 ({0}) ~= d9 ({1}): {2}", 
                        d1, d9, RoughlyEquals(d1, d9, window, freq));
	}
}
// The example displays output similar to the following: 
//    d1 (1/28/2010 9:01:26 PM) ~= d1 (1/28/2010 9:01:26 PM): True 
//    d1 (1/28/2010 9:01:26 PM) ~= d2 (1/28/2010 9:01:46 PM): False 
//    d1 (1/28/2010 9:01:26 PM) ~= d3 (1/28/2010 9:01:06 PM): False 
//    d1 (1/28/2010 9:01:26 PM) ~= d4 (1/28/2010 9:01:31 PM): True 
//    d1 (1/28/2010 9:01:26 PM) ~= d5 (1/28/2010 9:01:21 PM): True 
//    d1 (1/28/2010 9:01:26 PM) ~= d6 (1/28/2010 11:01:46 PM): False 
//    d1 (1/28/2010 9:01:26 PM) ~= d7 (1/28/2010 11:01:06 PM): False 
//    d1 (1/28/2010 9:01:26 PM) ~= d8 (1/28/2010 11:01:31 PM): True 
//    d1 (1/28/2010 9:01:26 PM) ~= d9 (1/28/2010 11:01:21 PM): True
bool RoughlyEquals( DateTime time, DateTime timeWithWindow, int windowInSeconds, int frequencyInSeconds )
{
   long delta = (long)((TimeSpan)(timeWithWindow - time)).TotalSeconds % frequencyInSeconds;
   delta = delta > windowInSeconds ? frequencyInSeconds - delta : delta;
   return Math::Abs( delta ) < windowInSeconds;
}

int main()
{
   int window = 10;
   int freq = 60 * 60 * 2; // 2 hours;

   DateTime d1 = DateTime::Now;
   DateTime d2 = d1.AddSeconds( 2 * window );
   DateTime d3 = d1.AddSeconds(  -2 * window );
   DateTime d4 = d1.AddSeconds( window / 2 );
   DateTime d5 = d1.AddSeconds(  -window / 2 );
   DateTime d6 = (d1.AddHours( 2 )).AddSeconds( 2 * window );
   DateTime d7 = (d1.AddHours( 2 )).AddSeconds(  -2 * window );
   DateTime d8 = (d1.AddHours( 2 )).AddSeconds( window / 2 );
   DateTime d9 = (d1.AddHours( 2 )).AddSeconds(  -window / 2 );

   Console::WriteLine("d1 ({0}) ~= d1 ({1}): {2}",
                      d1, d1, RoughlyEquals(d1, d1, window, freq));
   Console::WriteLine("d1 ({0}) ~= d2 ({1}): {2}", 
                      d1, d2, RoughlyEquals(d1, d2, window, freq));
   Console::WriteLine("d1 ({0}) ~= d3 ({1}): {2}", 
                      d1, d3, RoughlyEquals(d1, d3, window, freq));
   Console::WriteLine("d1 ({0}) ~= d4 ({1}): {2}", 
                      d1, d4, RoughlyEquals(d1, d4, window, freq));
   Console::WriteLine("d1 ({0}) ~= d5 ({1}): {2}", 
                      d1, d5, RoughlyEquals(d1, d5, window, freq));

   Console::WriteLine("d1 ({0}) ~= d6 ({1}): {2}", 
                      d1, d6, RoughlyEquals(d1, d6, window, freq));
   Console::WriteLine("d1 ({0}) ~= d7 ({1}): {2}", 
                      d1, d7, RoughlyEquals(d1, d7, window, freq));
   Console::WriteLine("d1 ({0}) ~= d8 ({1}): {2}", 
                      d1, d8, RoughlyEquals(d1, d8, window, freq));
   Console::WriteLine("d1 ({0}) ~= d9 ({1}): {2}", 
                      d1, d9, RoughlyEquals(d1, d9, window, freq));
}                     
// The example displays output similar to the following: 
//    d1 (1/28/2010 9:01:26 PM) ~= d1 (1/28/2010 9:01:26 PM): True 
//    d1 (1/28/2010 9:01:26 PM) ~= d2 (1/28/2010 9:01:46 PM): False 
//    d1 (1/28/2010 9:01:26 PM) ~= d3 (1/28/2010 9:01:06 PM): False 
//    d1 (1/28/2010 9:01:26 PM) ~= d4 (1/28/2010 9:01:31 PM): True 
//    d1 (1/28/2010 9:01:26 PM) ~= d5 (1/28/2010 9:01:21 PM): True 
//    d1 (1/28/2010 9:01:26 PM) ~= d6 (1/28/2010 11:01:46 PM): False 
//    d1 (1/28/2010 9:01:26 PM) ~= d7 (1/28/2010 11:01:06 PM): False 
//    d1 (1/28/2010 9:01:26 PM) ~= d8 (1/28/2010 11:01:31 PM): True 
//    d1 (1/28/2010 9:01:26 PM) ~= d9 (1/28/2010 11:01:21 PM): True
Version Information

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8
Platforms

Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Thread Safety

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.

Caution noteCaution

Assigning an instance of this type is not thread safe on all hardware platforms because the binary representation of that instance might be too large to assign in a single atomic operation.