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

◆ ticks()

int64 xtd::date_time::ticks ( ) const
noexcept

Gets the number of ticks that represent the date and time of this instance.

Returns
The number of ticks that represent the date and time of this instance. The value is between xtd::date_time::min_value.ticks and xtd::date_time::max_value.ticks.
Examples
The following example uses the xtd::date_time::ticks property to display the number of ticks that have elapsed since the beginning of the century.
#include <xtd/console>
#include <xtd/date_time>
#include <xtd/startup>
using namespace std::chrono;
using namespace xtd;
class program {
public:
static auto main() {
auto century_begin = date_time {2001, 1, 1};
auto current_date = date_time::now();
auto elapsed_ticks = current_date.ticks() - century_begin.ticks();
auto elapsed_span = time_span {elapsed_ticks};
console::write_line("Elapsed from the beginning of the century to {:f}:", current_date);
console::write_line(" {:N0} nanoseconds", elapsed_ticks * 100);
console::write_line(" {:N0} ticks", elapsed_ticks);
console::write_line(" {:N2} seconds", elapsed_span.total_seconds());
console::write_line(" {:N2} minutes", elapsed_span.total_minutes());
console::write_line(" {:N0} days, {} hours, {} minutes, {} seconds", elapsed_span.days(), elapsed_span.hours(),
elapsed_span.minutes(), elapsed_span.seconds());
}
};
startup_(program::main);
// This code can produce the following output :
//
// Elapsed from the beginning of the century to Wed Aug 16 22:46:16 2023:
// 713918776070706048 nanoseconds
// 7139187760707060 ticks
// 713918776.07 seconds
// 11898646.27 minutes
// 8262 days, 22 hours, 46 minutes, 16 seconds
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
Examples
date_time_ticks.cpp.