xtd 0.2.0
Loading...
Searching...
No Matches

◆ time_of_day()

xtd::time_span xtd::date_time::time_of_day ( ) const
noexcept

Gets the time of day for this instance.

Returns
A time interval that represents the fraction of the day that has elapsed since midnight.
Examples
The following example displays the value of the xtd::date_time::time_of_day property for an array of xtd::date_time values. It also contrasts the return value with the string returned by the "t" standard format string in a composite formatting operation.
#include <xtd/console>
#include <xtd/date_time>
#include <xtd/startup>
using namespace xtd;
class program {
public:
static auto main() {
// Get the current date.
auto this_day = date_time::today();
// Display the date in the default (general) format.
console::write_line(this_day.to_string());
console::write_line();
// Display the date in a variety of formats.
console::write_line(this_day.to_string("d"));
console::write_line(this_day.to_string("D"));
console::write_line(this_day.to_string("g"));
}
};
startup_(program::main);
// This code can produce the following output :
//
// Wed Jan 12 00:00:00 2022
//
// 01/12/2022
// 1/12/2022
// Wed Jan 12 00:00:00 2022
#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
Remarks
Unlike the xtd::date_time::date property. which returns a xtd::date_time value that represents a date without its time component, the xtd::date_time::time_of_day property returns a xtd::time_span value that represents a xtd::date_time value's time component.
If you want to display the time of day or retrieve the string representation of the time of day of a xtd::date_time value, you can instead call an overload of the ToString method that has a format parameter or use the composite formatting feature with the "t" or "T" standard format string.