TimeSpan

TimeSpan class

Represents a time interval. 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 TimeSpan

Methods

MethodDescription
TimeSpan Add(TimeSpan) constReturns a new instance of TimeSpan class that represents a time interval which is the sum of the time intervals represented by the current and the specified objects.
static constexpr int Compare(TimeSpan, TimeSpan)Compares two TimeSpan objects.
constexpr int CompareTo(TimeSpan) constCompares current and the specified objects.
int CompareTo(const SharedPtr<Object>&) constCompares current and the specified objects.
TimeSpan Duration() constReturns a new instance of TimeSpan object whose value is the absolute value of the current object.
constexpr bool Equals(TimeSpan) constDetermines if the time interval represented by the current object is equal to the time interval represented by the specified object.
bool Equals(const SharedPtr<Object>&) constDetermines if the time interval represented by the current object is equal to the time interval represented by the specified object.
static constexpr bool Equals(TimeSpan, TimeSpan)Returns true if the specified objects represent the same time interval, otherwise - false.
static TimeSpan FromDays(double)Returns a new TimeSpan object that represents the specified interval.
static TimeSpan FromHours(double)Returns a new TimeSpan object that represents the specified interval.
static TimeSpan FromMilliseconds(double)Returns a new TimeSpan object that represents the specified interval.
static TimeSpan FromMinutes(double)Returns a new TimeSpan object that represents the specified interval.
static TimeSpan FromSeconds(double)Returns a new TimeSpan object that represents the specified interval.
static constexpr TimeSpan FromTicks(int64_t)Returns a new TimeSpan object that represents the specified interval.
constexpr int get_Days() constReturns the days component of the time interval represented by the current TimeSpan object.
constexpr int get_Hours() constReturns the hours component of the time interval represented by the current TimeSpan object.
constexpr int get_Milliseconds() constReturns the milliseconds component of the time interval represented by the current TimeSpan object.
constexpr int get_Minutes() constReturns the minutes component of the time interval represented by the current TimeSpan object.
constexpr int get_Seconds() constReturns the seconds component of the time interval represented by the current TimeSpan object.
constexpr int64_t get_Ticks() constReturns the number of 100-nanoseconds intervals that constitute the time interval represented by the current TimeSpan object.
constexpr double get_TotalDays() constReturns the value of the current TimeSpan object expressed in whole and fractional days.
constexpr double get_TotalHours() constReturns the value of the current TimeSpan object expressed in whole and fractional hours.
double get_TotalMilliseconds() constReturns the value of the current TimeSpan object expressed in whole and fractional milliseconds.
constexpr double get_TotalMinutes() constReturns the value of the current TimeSpan object expressed in whole and fractional minutes.
constexpr double get_TotalSeconds() constReturns the value of the current TimeSpan object expressed in whole and fractional seconds.
int GetHashCode() constReturns a hash code for the current object.
constexpr bool IsNull() const
TimeSpan Negate() constReturns a new instance of TimeSpan object that represents negated value represented by the current TimeSpan object.
constexpr bool operator!=(TimeSpan) constDetermines if the time interval represented by the current object is not equal to the time interval represented by the specified object.
constexpr bool operator!=(std::nullptr_t) const
TimeSpan operator+(TimeSpan) constReturns a new instance of TimeSpan class that represents a time interval which is the sum of the time intervals represented by the current and the specified objects.
TimeSpan operator+() constReturns self.
TimeSpan& operator+=(TimeSpan)Assigns to the current object the time interval which is the sum of the time interval represented by the current and the specified objects.
TimeSpan operator-(TimeSpan) constReturns a new instance of TimeSpan class that represents a time interval which is the result of subtraction of the time interval represented by the specified object from the time interval represented by the current object.
TimeSpan operator-() constReturns a new instance of TimeSpan object that represents negated value represented by the current TimeSpan object.
TimeSpan& operator-=(TimeSpan)Assigns to the current object the time interval which is the result of subtraction of the time interval represented by the specified object from the time interval represented by the current object.
TimeSpan operator/(double) const
constexpr double operator/(TimeSpan) const
TimeSpan& operator/=(double)
constexpr bool operator<(TimeSpan) constDetermines if the time interval represented by the current object is shorter than the time interval represented by the specified object.
constexpr bool operator<(std::nullptr_t) const
constexpr bool operator<=(TimeSpan) constDetermines if the time interval represented by the current object is shorter than or equal to the time interval represented by the specified object.
constexpr bool operator<=(std::nullptr_t) const
constexpr TimeSpan& operator=(const TimeSpan&)Sets the time interval represented by the specified TimeSpan object to the current TimeSpan object.
constexpr bool operator==(TimeSpan) constDetermines if the time interval represented by the current object is equal to the time interval represented by the specified object.
constexpr bool operator==(std::nullptr_t) const
constexpr bool operator>(TimeSpan) constDetermines if the time interval represented by the current object is longer than the time interval represented by the specified object.
constexpr bool operator>(std::nullptr_t) const
constexpr bool operator>=(TimeSpan) constDetermines if the time interval represented by the current object is longer than or equal to the time interval represented by the specified object.
constexpr bool operator>=(std::nullptr_t) const
static TimeSpan Parse(const String&)Converts string to equivalent TimeSpan object.
static TimeSpan Parse(const String&, const SharedPtr<IFormatProvider>&)Converts string to equivalent TimeSpan object using the specified format provider.
static TimeSpan Parse(const String&, const SharedPtr<Globalization::CultureInfo>&)
static TimeSpan Parse(const String&, const SharedPtr<Globalization::DateTimeFormatInfo>&)
static TimeSpan Parse(const String&, std::nullptr_t)
static TimeSpan ParseExact(const String&, const ArrayPtr<String>&, const SharedPtr<IFormatProvider>&, Globalization::TimeSpanStyles)Converts string to equivalent TimeSpan object using the specified formats, format provider and styles.
static TimeSpan ParseExact(const String&, const ArrayPtr<String>&, const SharedPtr<Globalization::CultureInfo>&, Globalization::TimeSpanStyles)
static TimeSpan ParseExact(const String&, const ArrayPtr<String>&, const SharedPtr<Globalization::DateTimeFormatInfo>&, Globalization::TimeSpanStyles)
static TimeSpan ParseExact(const String&, const ArrayPtr<String>&, std::nullptr_t, Globalization::TimeSpanStyles)
static TimeSpan ParseExact(const String&, const String&, const SharedPtr<IFormatProvider>&, Globalization::TimeSpanStyles)Converts string to equivalent TimeSpan object using the specified format, format provider and styles.
static TimeSpan ParseExact(const String&, const String&, const SharedPtr<Globalization::CultureInfo>&, Globalization::TimeSpanStyles)
static TimeSpan ParseExact(const String&, const String&, const SharedPtr<Globalization::DateTimeFormatInfo>&, Globalization::TimeSpanStyles)
static TimeSpan ParseExact(const String&, const String&, std::nullptr_t, Globalization::TimeSpanStyles)
TimeSpan Subtract(TimeSpan) constReturns a new instance of TimeSpan class that represents a time interval which is the result of subtraction of the time interval represented by the specified object from the time interval represented by the current object.
constexpr TimeSpan()Constructs a TimeSpan object that represents a zero time interval.
explicit constexpr TimeSpan(int64_t)Constructs an instance of TimeSpan class that represents the specified time interval.
TimeSpan(int, int, int)Constructs an instance of TimeSpan class that represents the time interval which is equal to the sum of the specified number of hours, minutes and seconds.
TimeSpan(int, int, int, int, int)Constructs an instance of TimeSpan class that represents the time interval which is equal to the sum of the specified number of hours, minutes, seconds and milliseconds.
constexpr TimeSpan(const TimeSpan&)Constructs a TimeSpan object that represents the time interval equal to the time interval represented by the specified TimeSpan object.
String ToString() constReturns the string representation of the time interval represented by the current object.
String ToString(const String&) constConverts the value of the current object to equivalent string representation, using the specified format.
String ToString(const String&, const SharedPtr<IFormatProvider>&) constConverts the value of the current object to equivalent string representation, using the specified format and format provider.
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
static bool TryParse(const String&, TimeSpan&)Converts string to equivalent TimeSpan object and returns result of conversion.
static bool TryParse(const String&, const SharedPtr<IFormatProvider>&, TimeSpan&)Converts string to equivalent TimeSpan object using the specified format provider and returns result of conversion.
static bool TryParse(const String&, const SharedPtr<Globalization::CultureInfo>&, TimeSpan&)
static bool TryParse(const String&, const SharedPtr<Globalization::DateTimeFormatInfo>&, TimeSpan&)
static bool TryParse(const String&, std::nullptr_t, TimeSpan&)
static bool TryParseExact(const String&, const ArrayPtr<String>&, const SharedPtr<IFormatProvider>&, TimeSpan&)Converts string to equivalent TimeSpan object using the specified formats and format provider, and returns result of conversion.
static bool TryParseExact(const String&, const ArrayPtr<String>&, const SharedPtr<Globalization::CultureInfo>&, TimeSpan&)
static bool TryParseExact(const String&, const ArrayPtr<String>&, const SharedPtr<Globalization::DateTimeFormatInfo>&, TimeSpan&)
static bool TryParseExact(const String&, const ArrayPtr<String>&, std::nullptr_t, TimeSpan&)
static bool TryParseExact(const String&, const String&, const SharedPtr<IFormatProvider>&, Globalization::TimeSpanStyles, TimeSpan&)Converts string to equivalent TimeSpan object using the specified format, format provider and styles, and returns result of conversion.
static bool TryParseExact(const String&, const String&, const SharedPtr<Globalization::CultureInfo>&, Globalization::TimeSpanStyles, TimeSpan&)
static bool TryParseExact(const String&, const String&, const SharedPtr<Globalization::DateTimeFormatInfo>&, Globalization::TimeSpanStyles, TimeSpan&)
static bool TryParseExact(const String&, const String&, std::nullptr_t, Globalization::TimeSpanStyles, TimeSpan&)
static bool TryParseExact(const String&, const ArrayPtr<String>&, const SharedPtr<IFormatProvider>&, Globalization::TimeSpanStyles, TimeSpan&)Converts string to equivalent TimeSpan object using the specified formats, format provider and styles, and returns result of conversion.
static bool TryParseExact(const String&, const ArrayPtr<String>&, const SharedPtr<Globalization::CultureInfo>&, Globalization::TimeSpanStyles, TimeSpan&)
static bool TryParseExact(const String&, const ArrayPtr<String>&, const SharedPtr<Globalization::DateTimeFormatInfo>&, Globalization::TimeSpanStyles, TimeSpan&)
static bool TryParseExact(const String&, const ArrayPtr<String>&, std::nullptr_t, Globalization::TimeSpanStyles, TimeSpan&)
static bool TryParseExact(const String&, const String&, const SharedPtr<IFormatProvider>&, TimeSpan&)Converts string to equivalent TimeSpan object using the specified format and format provider, and returns result of conversion.
static bool TryParseExact(const String&, const String&, const SharedPtr<Globalization::CultureInfo>&, TimeSpan&)
static bool TryParseExact(const String&, const String&, const SharedPtr<Globalization::DateTimeFormatInfo>&, TimeSpan&)
static bool TryParseExact(const String&, const String&, std::nullptr_t, TimeSpan&)
static const TypeInfo& Type()Returns a TypeInfo object that represent TimeSpan structure.

Fields

FieldDescription
static MaxValueThe TimeSpan object that represents the longest possible interval.
static MinValue/// The TimeSpan object that represents the shortest possible interval.
static constexpr TicksPerDayThe number of 100-nanoseconds intervals in a day (24-hour interval).
static constexpr TicksPerHourThe number of 100-nanoseconds intervals in a hour.
static constexpr TicksPerMillisecondThe number of 100-nanoseconds intervals in a millisecond.
static constexpr TicksPerMinuteThe number of 100-nanoseconds intervals in a minute.
static constexpr TicksPerSecondThe number of 100-nanoseconds intervals in a second.
static ZeroThe TimeSpan object that represents zero-interval.

Remarks

#include "system/datetime.h"
#include "system/timespan.h"
#include <iostream>

int main()
{
  const auto date1 = System::DateTime(2021, 01, 01);
  const auto date2 = System::DateTime(2021, 10, 30);

  const auto interval = date2 - date1;

  std::cout << "Number of ticks: " << interval.get_Ticks() << std::endl;
  std::cout << "Number of milliseconds: " << interval.get_Milliseconds() << std::endl;
  std::cout << "Total number of milliseconds: " << interval.get_TotalMilliseconds() << std::endl;
  std::cout << "Number of minutes: " << interval.get_Minutes() << std::endl;
  std::cout << "Total number of minutes: " << interval.get_TotalMinutes() << std::endl;
  std::cout << "Number of hours: " << interval.get_Hours() << std::endl;
  std::cout << "Total number of hours: " << interval.get_Hours() << std::endl;
  std::cout << "Number of days: " << interval.get_Days() << std::endl;
  std::cout << "Total number of days: " << interval.get_TotalDays() << std::endl;

  return 0;
}
/*
This code example produces the following output:
Number of ticks: 260928000000000
Number of milliseconds: 0
Total number of milliseconds: 2.60928e+10
Number of minutes: 0
Total number of minutes: 434880
Number of hours: 0
Total number of hours: 0
Number of days: 302
Total number of days: 302
*/

See Also