System::DateTime class

DateTime class

Represents a specific date and time value on the time continuum. This type should be allocated on stack and passed to functions by value or by reference. Never use System::SmartPtr class to manage objects of this type.

class DateTime

Methods

MethodDescription
Add(TimeSpan) constReturns a new instance of DateTime class that represents a date and time value that results from addition of the specified time span to the date and time value represented by the current object.
AddDays(double) constReturns a new instance of the DateTime class representing the date and time value which is the sum of the value represented by the current object and the specified number of days.
AddHours(double) constReturns a new instance of the DateTime class representing the date and time value which is the sum of the value represented by the current object and the specified number of hours.
AddMilliseconds(double) constReturns a new instance of the DateTime class representing the date and time value which is the sum of the value represented by the current object and the specified number of milliseconds.
AddMinutes(double) constReturns a new instance of the DateTime class representing the date and time value which is the sum of the value represented by the current object and the specified number of minutes.
AddMonths(int) constReturns a new instance of the DateTime class representing the date and time value which is the sum of the value represented by the current object and the specified number of months.
AddSeconds(double) constReturns a new instance of the DateTime class representing the date and time value which is the sum of the value represented by the current object and the specified number of seconds.
AddTicks(int64_t) constReturns a new instance of the DateTime class representing the date and time value which is the sum of the value represented by the current object and the specified number of 100-nanosecond intervals.
AddYears(int) constReturns a new instance of the DateTime class representing the date and time value equal to that represented by the current object with the year component increased by the specified number.
static Compare(DateTime, DateTime)Compares two values represented by the specified instances of DateTime class and returns the value indicating values’ relative positions on the time line.
CompareTo(DateTime) constCompares two date and time values represented by the current object and the specified instance of DateTime class and returns the value indicating values’ relative positions on the time line.
DateTime()Constructs an instance that represents the smallest possible date and time value equal to MinValue.
DateTime(int, int, int)Constructs an instance that represents a date and time value specified as a particular year, month and day.
DateTime(int, int, int, const SharedPtr<Globalization::Calendar>&)Constructs an instance that represents a date and time value specified as a particular year, month and day in the specified calendar.
DateTime(int, int, int, int, int, int)Constructs an instance that represents a date and time value specified as a particular year, month, day, hour, minute and second.
DateTime(int, int, int, int, int, int, DateTimeKind)Constructs an instance that represents a date and time value specified as a particular year, month, day, hour, minute and second.
DateTime(int, int, int, int, int, int, const SharedPtr<Globalization::Calendar>&)Constructs an instance that represents a date and time value specified as a particular year, month, day, hour, minute and second in the specified calendar.
DateTime(int, int, int, int, int, int, int, DateTimeKind)Constructs an instance that represents a date and time value specified as a particular year, month, day, hour, minute, second and millisecond.
DateTime(int, int, int, int, int, int, int, const SharedPtr<Globalization::Calendar>&, DateTimeKind)Constructs an instance that represents a date and time value specified as a particular year, month, day, hour, minute, second and millisecond in the specified calendar.
DateTime(int64_t, DateTimeKind)Construct an instance that represents a date and time value specified as a number of ticks.
DateTime(int64_t, DateTimeKind, bool)Construct an instance that represents a date and time value specified as a number of ticks. FOR INTERNAL USE.
DateTime(const DateTime&)Copy-constructs an instance.
static DaysInMonth(int, int)Returns the number of days in the specified month of the specified year.
static Equals(DateTime, DateTime)Determines if the specified instances of DateTime class represent the same date and time value.
Equals(DateTime) constDetermines if the specified instance of DateTime class represent the same date and time value as the current object.
static FromBinary(int64_t)Deserializes the date time value from the specified unsigned 64-bit integer and sets the new instance of DateTime class to that value.
static FromFileTime(int64_t)Converts the specified File time to an instance of DateTime class representing the same date and time value as local time.
static FromFileTimeUtc(int64_t)Converts the specified File time to an instance of DateTime class representing the same date and time value as UTC time.
static FromOADate(double)Returns an instance of DateTime class representing the date and time value equivalent to the specified OLE Automation Date.
static FromUnixTime(time_t)Converts the specified Unix time value to an instance of DateTime class. FOR INTERNAL USE.
get_Date() constReturns a new instance of DateTime class that represents the date portion of the date and time represented by the current object with each component of the time portion set to 0.
get_Day() constReturns the ordinal number of the day in the month represented by the current object.
get_DayOfWeek() constReturns a value representing a day of week that is represented by the current object.
get_DayOfYear() constReturns the ordinal number of the day in the year represented by the current object.
get_Hour() constReturns the hour component of the date and time value represented by the current object.
get_Kind() constReturns the value representing if the date and time represented by the current object is a local or UTC date and time or neither.
get_Millisecond() constReturns the millisecond component of the date and time value represented by the current object.
get_Minute() constReturns the minute component of the date and time value represented by the current object.
get_Month() constReturns the ordinal number of the month in the year represented by the current object.
static get_Now()Returns an instance of DateTime class that represents the current time as local time.
get_Second() constReturns the second component of the date and time value represented by the current object.
get_Ticks() constReturns a number of 100-nanosecond intervals passed since 0:00:00 UTC, January 1, 0001, in the Gregorian calendar until the date and time represented by the current object.
get_TimeOfDay() constReturns the value that represents the time interval from the beginning of the day represented by the current object till the date and time value represented by the current object.
static get_Today()Returns an instance of DateTime class that represents the current date with each component of time portion of the value represented by the object set to 0.
static get_UtcNow()Returns an instance of DateTime class that represents the current time as UTC.
get_Year() constReturns the year represented by the current object.
GetDateComponents(int&, int&, int&) constGets date parts. FOR INTERNAL USE.
GetDateTimeFormats() constReturns array of strings where each element is the string representation of the current object formatted with one of the standard date and time format specifiers.
GetDateTimeFormats(char_t) constReturns array of strings where each element is the string representation of the current object formatted with the specified standard date and time format specifier.
GetDateTimeFormats(const SharedPtr<IFormatProvider>&) constReturns array of strings where each element is the string representation of the current object formatted with one of the standard date and time format specifiers and the specified format provider.
GetDateTimeFormats(char_t, const SharedPtr<IFormatProvider>&) constReturns array of strings where each element is the string representation of the current object formatted with the specified standard date and time format specifier and format provider.
GetHashCode() constReturns a hash code for the current object.
IsDaylightSavingTime() constDetermines if the date and time value represented by the current object falls in the range of daylight saving time for the current time zone.
static IsLeapYear(int)Determines of the specified year is a leap year.
IsNull() const
operator!=(DateTime) constDetermines if the current object and the specified DateTime object represent distinct date and time values.
operator!=(std::nullptr_t) const
operator+(TimeSpan) constReturns a new instance of DateTime class that represents the date and time value that is the sum of the value represented by the current object and the specified time span.
operator+=(TimeSpan)Sets the current object to the date and time value that is the sum of the value represented by the current object and the specified time span.
operator-(TimeSpan) constReturns a new instance of the DateTime class representing the date and time value which is the result of subtraction of the specified time span from the value represented by the current object.
operator-(DateTime) constReturns an instance of TimeSpan class that represents the time interval between the date and time values represented by the current and the specified objects.
operator-=(TimeSpan)Sets the current object to the date and time value that is the result of subtraction of the specified time span from the date and time value represented by the current object.
operator<(DateTime) constDetermines if the current object represents the date and time value that is earlier than the value represented by the specified DateTime object.
operator<(std::nullptr_t) const
operator<=(DateTime) constDetermines if the current object represents the date and time value that is earlier than or the same as the value represented by the specified DateTime object.
operator<=(std::nullptr_t) const
operator=(const DateTime&)Assigns the value represented by the specified DateTime instance to the current object.
operator==(DateTime) constDetermines if the current object and the specified DateTime object represent the same date and time value.
operator==(std::nullptr_t) const
operator>(DateTime) constDetermines if the current object represents the date and time value that is later than the value represented by the specified DateTime object.
operator>(std::nullptr_t) const
operator>=(DateTime) constDetermines if the current object represents the date and time value that is later than or the same as the value represented by the specified DateTime object.
operator>=(std::nullptr_t) const
static Parse(const String&)Converts the specified string representation of a date and time value to the equivalent DateTime object.
static Parse(const String&, const SharedPtr<IFormatProvider>&, Globalization::DateTimeStyles)Converts the specified string representation of a date and time value to the equivalent DateTime object using culture-specific format information.
static Parse(const String&, const SharedPtr<Globalization::CultureInfo>&, Globalization::DateTimeStyles)
static Parse(const String&, const SharedPtr<Globalization::DateTimeFormatInfo>&, Globalization::DateTimeStyles)
static Parse(const String&, std::nullptr_t, Globalization::DateTimeStyles)
static ParseExact(const String&, const String&, const SharedPtr<IFormatProvider>&, Globalization::DateTimeStyles)Converts the specified string representation of a date and time value to the equivalent DateTime object using the specified format and culture-specific format information. The format of the string representation must match the specified format exactly. Throws an exception if the conversion fails.
static ParseExact(const String&, const String&, const SharedPtr<Globalization::CultureInfo>&, Globalization::DateTimeStyles)
static ParseExact(const String&, const String&, const SharedPtr<Globalization::DateTimeFormatInfo>&, Globalization::DateTimeStyles)
static ParseExact(const String&, const String&, std::nullptr_t, Globalization::DateTimeStyles)
static ParseExact(const String&, const ArrayPtr<String>&, const SharedPtr<IFormatProvider>&, Globalization::DateTimeStyles)Converts the specified string representation of a date and time value to the equivalent DateTime object using the specified formats, culture-specific format information and style. The format of the string representation must match one or more of the specified formats exactly. Throws an exception if the conversion fails.
static ParseExact(const String&, const ArrayPtr<String>&, const SharedPtr<Globalization::CultureInfo>&, Globalization::DateTimeStyles)
static ParseExact(const String&, const ArrayPtr<String>&, const SharedPtr<Globalization::DateTimeFormatInfo>&, Globalization::DateTimeStyles)
static ParseExact(const String&, const ArrayPtr<String>&, std::nullptr_t, Globalization::DateTimeStyles)
static SpecifyKind(DateTime, DateTimeKind)Constructs a new DateTime object that represents the same number of ticks as the specified DateTime object and represents local time, UTC time or neither as specified by the argument kind.
Subtract(TimeSpan) constReturns a new instance of the DateTime class representing the date and time value which is the result of subtraction of the specified time span from the value represented by the current object.
Subtract(DateTime) constReturns an instance of TimeSpan class representing the time interval between the date and time values represented by the current and the specified objects.
ToBinary() constSerializes the current object.
ToFileTime() constReturns a value that represents the date and time value represented by the current object as File time.
ToFileTimeUtc() constConverts the date and time value represented by the current object to File time UTC.
ToLocalTime() constReturns a new instance of DateTime class that represents the date and time value represented by the current object as local time.
ToLongDateString() constReturns a string that contains the long date string representation of the current object.
ToLongTimeString() constReturns a string that contains the long time string representation of the current object.
ToOADate() constReturns the date and time value represented by the current object as OLE Automation Date.
ToShortDateString() constReturns a string that contains the short date string representation of the current object.
ToShortTimeString() constReturns a string that contains the short time string representation of the current object.
ToString() constReturns the string representation of the date and time value represented by the current object using the formatting conventions defined by the current culture.
ToString(const String&) constReturns a string representation of the date and time value represented by the current object using the specified format and formatting conventions defined by the current culture.
ToString(const SharedPtr<IFormatProvider>&) constReturns a string representation of the date and time value represented by the current object using the specified format information.
ToString(const SharedPtr<Globalization::CultureInfo>&) const
ToString(const SharedPtr<Globalization::DateTimeFormatInfo>&) const
ToString(std::nullptr_t) const
ToString(const String&, const SharedPtr<IFormatProvider>&) constReturns a string representation of the date and time value represented by the current object using the specified format information.
ToString(const String&, const SharedPtr<Globalization::CultureInfo>&) const
ToString(const String&, const SharedPtr<Globalization::DateTimeFormatInfo>&) const
ToString(const String&, std::nullptr_t) const
ToUniversalTime() constReturns a new instance of DateTime class that represents the date and time value represented by the current object as UTC.
ToUnixTime() constReturns a value that represents the date and time value represented by the current object as Unix time. FOR INTERNAL USE.
static TryParse(const String&, DateTime&)Converts the specified string representation of a date and time value to the equivalent DateTime object.
static TryParse(const String&, const SharedPtr<IFormatProvider>&, Globalization::DateTimeStyles, DateTime&)Converts the specified string representation of a date and time value to the equivalent DateTime object using the specified culture-specific format information and style.
static TryParse(const String&, const SharedPtr<Globalization::CultureInfo>&, Globalization::DateTimeStyles, DateTime&)
static TryParse(const String&, const SharedPtr<Globalization::DateTimeFormatInfo>&, Globalization::DateTimeStyles, DateTime&)
static TryParse(const String&, std::nullptr_t, Globalization::DateTimeStyles, DateTime&)
static TryParseExact(const String&, const String&, const SharedPtr<IFormatProvider>&, Globalization::DateTimeStyles, DateTime&)Converts the specified string representation of a date and time value to the equivalent DateTime object using the specified format, culture-specific format information and style. The format of the string representation must match the specified format exactly.
static TryParseExact(const String&, const String&, const SharedPtr<Globalization::CultureInfo>&, Globalization::DateTimeStyles, DateTime&)
static TryParseExact(const String&, const String&, const SharedPtr<Globalization::DateTimeFormatInfo>&, Globalization::DateTimeStyles, DateTime&)
static TryParseExact(const String&, const String&, std::nullptr_t, Globalization::DateTimeStyles, DateTime&)
static TryParseExact(const String&, const ArrayPtr<String>&, const SharedPtr<IFormatProvider>&, Globalization::DateTimeStyles, DateTime&)Converts the specified string representation of a date and time value to the equivalent DateTime object using the specified formats, culture-specific format information and style. The format of the string representation must match one or more of the specified formats exactly.
static TryParseExact(const String&, const ArrayPtr<String>&, const SharedPtr<Globalization::CultureInfo>&, Globalization::DateTimeStyles, DateTime&)
static TryParseExact(const String&, const ArrayPtr<String>&, const SharedPtr<Globalization::DateTimeFormatInfo>&, Globalization::DateTimeStyles, DateTime&)
static TryParseExact(const String&, const ArrayPtr<String>&, std::nullptr_t, Globalization::DateTimeStyles, DateTime&)
static Type()Returns a TypeInfo object that contains information about this class.

Fields

FieldDescription
static constexpr MaxTicksThe number of 100-nanosecond in the time interval between the minimal possible and maximal possible DateTime value.
static MaxValueAn instance of DateTime class that represents the maximal possible date and time value.
static constexpr MinTicksThe minimal number of ticks that an instance of DateTime class can represent.
static MinValueAn instance of DateTime class that represents the minimal possible date and time value.
static constexpr TicksPerDayThe number of ticks in a day.
static constexpr TicksPerHourThe number of ticks in a hour.
static constexpr TicksPerMicrosecondThe number of ticks in a microsecond.
static constexpr TicksPerMillisecondThe number of ticks in a millisecond.
static constexpr TicksPerMinuteThe number of ticks in a minute.
static constexpr TicksPerSecondThe number of ticks in a second.
static UnixEpochAn instance of DateTime class that represents the Unix epoch start (1970.01.01 00:00:00).

Remarks

#include "system/console.h"
#include "system/date_time.h"

int main()
{
  using namespace System;

  // Create the 'DateTime' class instance.
  DateTime dateTime{1990, 10, 30};

  // Print the instance in the multiple formats.
  Console::WriteLine(dateTime.ToShortDateString());
  Console::WriteLine(dateTime.ToShortTimeString());
  Console::WriteLine(dateTime.ToString());

  return 0;
}
/*
This code example produces the following output:
30.10.1990
0:00
30.10.1990 0:00:00
*/

See Also