xtd 0.2.0
Loading...
Searching...
No Matches
time_span.cpp

Demonstrates the xtd::time_span struct.

#include <xtd/console>
#include <xtd/startup>
#include <xtd/date_time>
#include <xtd/time_span>
using namespace xtd;
namespace uri_example {
class program {
public:
// The main entry point for the application.
static auto main() {
// Define two dates.
auto date1 = date_time {2010, 1, 1, 8, 0, 15};
auto date2 = date_time {2010, 8, 18, 13, 30, 30};
// Calculate the interval between the two dates.
time_span interval = date2 - date1;
console::write_line("{0} - {1} = {2}", date2, date1, interval.to_string());
// Display individual properties of the resulting TimeSpan object.
console::write_line(" {0,-35} {1,20}", "Value of Days Component:", interval.days());
console::write_line(" {0,-35} {1,20}", "Total Number of Days:", interval.total_days());
console::write_line(" {0,-35} {1,20}", "Value of Hours Component:", interval.hours());
console::write_line(" {0,-35} {1,20}", "Total Number of Hours:", interval.total_hours());
console::write_line(" {0,-35} {1,20}", "Value of Minutes Component:", interval.minutes());
console::write_line(" {0,-35} {1,20}", "Total Number of Minutes:", interval.total_minutes());
console::write_line(" {0,-35} {1,20:N0}", "Value of Seconds Component:", interval.seconds());
console::write_line(" {0,-35} {1,20:N0}", "Total Number of Seconds:", interval.total_seconds());
console::write_line(" {0,-35} {1,20:N0}", "Value of Milliseconds Component:", interval.milliseconds());
console::write_line(" {0,-35} {1,20:N0}", "Total Number of Milliseconds:", interval.total_milliseconds());
console::write_line(" {0,-35} {1,20:N0}", "Ticks:", interval.ticks());
}
};
}
startup_(uri_example::program::main);
// This code produces the following output :
//
// Wed Aug 18 13:30:30 2010 - Fri Jan 1 08:00:15 2010 = 229.05:30:15
// Value of Days Component: 229
// Total Number of Days: 229.229340277778
// Value of Hours Component: 5
// Total Number of Hours: 5501.50416666667
// Value of Minutes Component: 30
// Total Number of Minutes: 330090.25
// Value of Seconds Component: 15
// Total Number of Seconds: 19,805,415
// Value of Milliseconds Component: 0
// Total Number of Milliseconds: 19,805,415,000
// Ticks: 198,054,150,000,000
Represents an instant in time, typically expressed as a date and time of day.
Definition date_time.h:85
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.h:175
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Represents a time interval.
Definition time_span.h:29
double total_milliseconds() const noexcept
Gets the value of the current xtd::time_span structure expressed in whole and fractional milliseconds...
int32 milliseconds() const noexcept
Gets the milliseconds component of the time interval represented by the current xtd::time_span struct...
double total_seconds() const noexcept
Gets the value of the current xtd::time_span structure expressed in whole and fractional seconds.
double total_days() const noexcept
Gets the value of the current xtd::time_span structure expressed in whole and fractional days.
xtd::string to_string() const noexcept override
Returns a xtd::string that represents the current object.
int32 days() const noexcept
Gets the days component of the time interval represented by the current xtd::time_span structure.
int32 seconds() const noexcept
Gets the seconds component of the time interval represented by the current xtd::time_span structure.
int32 minutes() const noexcept
Gets the minutes component of the time interval represented by the current xtd::time_span structure.
int64 ticks() const noexcept
Gets the number of ticks that represent the value of the current xtd::time_span structure.
double total_hours() const noexcept
Gets the value of the current xtd::time_span structure expressed in whole and fractional hours.
double total_minutes() const noexcept
Gets the value of the current xtd::time_span structure expressed in whole and fractional minutes.
int32 hours() const noexcept
Gets the hours component of the time interval represented by the current xtd::time_span structure.