DateTime
Contents
[
Hide
]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
Method | Description |
---|---|
DateTime Add(TimeSpan) const | Returns 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. |
DateTime AddDays(double) const | Returns 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. |
DateTime AddHours(double) const | Returns 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. |
DateTime AddMilliseconds(double) const | Returns 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. |
DateTime AddMinutes(double) const | Returns 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. |
DateTime AddMonths(int) const | Returns 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. |
DateTime AddSeconds(double) const | Returns 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. |
DateTime AddTicks(int64_t) const | Returns 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. |
DateTime AddYears(int) const | Returns 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 constexpr int 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. |
constexpr int CompareTo(DateTime) const | Compares 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. |
constexpr 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 int DaysInMonth(int, int) | Returns the number of days in the specified month of the specified year. |
static constexpr bool Equals(DateTime, DateTime) | Determines if the specified instances of DateTime class represent the same date and time value. |
constexpr bool Equals(DateTime) const | Determines if the specified instance of DateTime class represent the same date and time value as the current object. |
static DateTime 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 DateTime 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 DateTime 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 DateTime FromOADate(double) | Returns an instance of DateTime class representing the date and time value equivalent to the specified OLE Automation Date. |
static DateTime FromUnixTime(time_t) | Converts the specified Unix time value to an instance of DateTime class. FOR INTERNAL USE. |
constexpr DateTime get_Date() const | Returns 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. |
int get_Day() const | Returns the ordinal number of the day in the month represented by the current object. |
constexpr DayOfWeek get_DayOfWeek() const | Returns a value representing a day of week that is represented by the current object. |
int get_DayOfYear() const | Returns the ordinal number of the day in the year represented by the current object. |
constexpr int get_Hour() const | Returns the hour component of the date and time value represented by the current object. |
constexpr DateTimeKind get_Kind() const | Returns the value representing if the date and time represented by the current object is a local or UTC date and time or neither. |
constexpr int get_Millisecond() const | Returns the millisecond component of the date and time value represented by the current object. |
constexpr int get_Minute() const | Returns the minute component of the date and time value represented by the current object. |
int get_Month() const | Returns the ordinal number of the month in the year represented by the current object. |
static DateTime get_Now() | Returns an instance of DateTime class that represents the current time as local time. |
constexpr int get_Second() const | Returns the second component of the date and time value represented by the current object. |
constexpr int64_t get_Ticks() const | Returns 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. |
constexpr TimeSpan get_TimeOfDay() const | Returns 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 DateTime 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 DateTime get_UtcNow() | Returns an instance of DateTime class that represents the current time as UTC. |
int get_Year() const | Returns the year represented by the current object. |
void GetDateComponents(int&, int&, int&) const | Gets date parts. FOR INTERNAL USE. |
ArrayPtr<String> GetDateTimeFormats() const | Returns 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. |
ArrayPtr<String> GetDateTimeFormats(char_t) const | Returns array of strings where each element is the string representation of the current object formatted with the specified standard date and time format specifier. |
ArrayPtr<String> GetDateTimeFormats(const SharedPtr<IFormatProvider>&) const | Returns 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. |
ArrayPtr<String> GetDateTimeFormats(char_t, const SharedPtr<IFormatProvider>&) const | Returns 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. |
int GetHashCode() const | Returns a hash code for the current object. |
bool IsDaylightSavingTime() const | Determines 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 bool IsLeapYear(int) | Determines of the specified year is a leap year. |
constexpr bool IsNull() const | |
constexpr bool operator!=(DateTime) const | Determines if the current object and the specified DateTime object represent distinct date and time values. |
constexpr bool operator!=(std::nullptr_t) const | |
DateTime operator+(TimeSpan) const | Returns 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. |
DateTime& 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. |
DateTime operator-(TimeSpan) const | Returns 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. |
constexpr TimeSpan operator-(DateTime) const | Returns an instance of TimeSpan class that represents the time interval between the date and time values represented by the current and the specified objects. |
DateTime& 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. |
constexpr bool operator<(DateTime) const | Determines if the current object represents the date and time value that is earlier than the value represented by the specified DateTime object. |
constexpr bool operator<(std::nullptr_t) const | |
constexpr bool operator<=(DateTime) const | Determines 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. |
constexpr bool operator<=(std::nullptr_t) const | |
DateTime& operator=(const DateTime&) | Assigns the value represented by the specified DateTime instance to the current object. |
constexpr bool operator==(DateTime) const | Determines if the current object and the specified DateTime object represent the same date and time value. |
constexpr bool operator==(std::nullptr_t) const | |
constexpr bool operator>(DateTime) const | Determines if the current object represents the date and time value that is later than the value represented by the specified DateTime object. |
constexpr bool operator>(std::nullptr_t) const | |
constexpr bool operator>=(DateTime) const | Determines 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. |
constexpr bool operator>=(std::nullptr_t) const | |
static DateTime Parse(const String&) | Converts the specified string representation of a date and time value to the equivalent DateTime object. |
static DateTime 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 DateTime Parse(const String&, const SharedPtr<Globalization::CultureInfo>&, Globalization::DateTimeStyles) | |
static DateTime Parse(const String&, const SharedPtr<Globalization::DateTimeFormatInfo>&, Globalization::DateTimeStyles) | |
static DateTime Parse(const String&, std::nullptr_t, Globalization::DateTimeStyles) | |
static DateTime 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 DateTime ParseExact(const String&, const String&, const SharedPtr<Globalization::CultureInfo>&, Globalization::DateTimeStyles) | |
static DateTime ParseExact(const String&, const String&, const SharedPtr<Globalization::DateTimeFormatInfo>&, Globalization::DateTimeStyles) | |
static DateTime ParseExact(const String&, const String&, std::nullptr_t, Globalization::DateTimeStyles) | |
static DateTime 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 DateTime ParseExact(const String&, const ArrayPtr<String>&, const SharedPtr<Globalization::CultureInfo>&, Globalization::DateTimeStyles) | |
static DateTime ParseExact(const String&, const ArrayPtr<String>&, const SharedPtr<Globalization::DateTimeFormatInfo>&, Globalization::DateTimeStyles) | |
static DateTime ParseExact(const String&, const ArrayPtr<String>&, std::nullptr_t, Globalization::DateTimeStyles) | |
static DateTime 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. |
DateTime Subtract(TimeSpan) const | Returns 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. |
constexpr TimeSpan Subtract(DateTime) const | Returns an instance of TimeSpan class representing the time interval between the date and time values represented by the current and the specified objects. |
int64_t ToBinary() const | Serializes the current object. |
int64_t ToFileTime() const | Returns a value that represents the date and time value represented by the current object as File time. |
int64_t ToFileTimeUtc() const | Converts the date and time value represented by the current object to File time UTC. |
DateTime ToLocalTime() const | Returns a new instance of DateTime class that represents the date and time value represented by the current object as local time. |
String ToLongDateString() const | Returns a string that contains the long date string representation of the current object. |
String ToLongTimeString() const | Returns a string that contains the long time string representation of the current object. |
double ToOADate() const | Returns the date and time value represented by the current object as OLE Automation Date. |
String ToShortDateString() const | Returns a string that contains the short date string representation of the current object. |
String ToShortTimeString() const | Returns a string that contains the short time string representation of the current object. |
String ToString() const | Returns the string representation of the date and time value represented by the current object using the formatting conventions defined by the current culture. |
String ToString(const String&) const | Returns 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. |
String ToString(const SharedPtr<IFormatProvider>&) const | Returns a string representation of the date and time value represented by the current object using the specified format information. |
String ToString(const SharedPtr<Globalization::CultureInfo>&) const | |
String ToString(const SharedPtr<Globalization::DateTimeFormatInfo>&) const | |
String ToString(std::nullptr_t) const | |
String ToString(const String&, const SharedPtr<IFormatProvider>&) const | Returns a string representation of the date and time value represented by the current object using the specified format information. |
String ToString(const String&, const SharedPtr<Globalization::CultureInfo>&) const | |
String ToString(const String&, const SharedPtr<Globalization::DateTimeFormatInfo>&) const | |
String ToString(const String&, std::nullptr_t) const | |
DateTime ToUniversalTime() const | Returns a new instance of DateTime class that represents the date and time value represented by the current object as UTC. |
time_t ToUnixTime() const | Returns a value that represents the date and time value represented by the current object as Unix time. FOR INTERNAL USE. |
static bool TryParse(const String&, DateTime&) | Converts the specified string representation of a date and time value to the equivalent DateTime object. |
static bool 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 bool TryParse(const String&, const SharedPtr<Globalization::CultureInfo>&, Globalization::DateTimeStyles, DateTime&) | |
static bool TryParse(const String&, const SharedPtr<Globalization::DateTimeFormatInfo>&, Globalization::DateTimeStyles, DateTime&) | |
static bool TryParse(const String&, std::nullptr_t, Globalization::DateTimeStyles, DateTime&) | |
static bool 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 bool TryParseExact(const String&, const String&, const SharedPtr<Globalization::CultureInfo>&, Globalization::DateTimeStyles, DateTime&) | |
static bool TryParseExact(const String&, const String&, const SharedPtr<Globalization::DateTimeFormatInfo>&, Globalization::DateTimeStyles, DateTime&) | |
static bool TryParseExact(const String&, const String&, std::nullptr_t, Globalization::DateTimeStyles, DateTime&) | |
static bool 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 bool TryParseExact(const String&, const ArrayPtr<String>&, const SharedPtr<Globalization::CultureInfo>&, Globalization::DateTimeStyles, DateTime&) | |
static bool TryParseExact(const String&, const ArrayPtr<String>&, const SharedPtr<Globalization::DateTimeFormatInfo>&, Globalization::DateTimeStyles, DateTime&) | |
static bool TryParseExact(const String&, const ArrayPtr<String>&, std::nullptr_t, Globalization::DateTimeStyles, DateTime&) | |
static const TypeInfo& Type() | Returns a TypeInfo object that contains information about this class. |
Fields
Field | Description |
---|---|
static constexpr MaxTicks | The number of 100-nanosecond in the time interval between the minimal possible and maximal possible DateTime value. |
static MaxValue | An instance of DateTime class that represents the maximal possible date and time value. |
static constexpr MinTicks | The minimal number of ticks that an instance of DateTime class can represent. |
static MinValue | An instance of DateTime class that represents the minimal possible date and time value. |
static constexpr TicksPerDay | The number of ticks in a day. |
static constexpr TicksPerHour | The number of ticks in a hour. |
static constexpr TicksPerMicrosecond | The number of ticks in a microsecond. |
static constexpr TicksPerMillisecond | The number of ticks in a millisecond. |
static constexpr TicksPerMinute | The number of ticks in a minute. |
static constexpr TicksPerSecond | The number of ticks in a second. |
static UnixEpoch | An 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
- Namespace System
- Library Aspose.Slides