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

Shows how to use xtd::date_time::add_seconds method.

#include <xtd/console>
#include <xtd/date_time>
#include <xtd/startup>
#include <xtd/string>
using namespace xtd;
class program {
public:
static auto main() {
auto date_format = "{0:d}/{0:t}.{0:c}"_s;
auto date1 = date_time {2014, 9, 8, 16, 0, 0};
console::write_line("Original date: {0} ({1:N0} ticks)\n", string::format(date_format, date1), date1.ticks());
auto date2 = date1.add_seconds(30);
console::write_line("Second date: {0} ({1:N0} ticks)", string::format(date_format, date2), date2.ticks());
console::write_line("Difference between dates: {0} ({1:N0} ticks)\n", date2 - date1, date2.ticks() - date1.ticks());
// Add 1 day's worth of seconds (60 secs. * 60 mins * 24 hrs.r
auto date3 = date1.add_seconds(60 * 60 * 24);
console::write_line("Third date: {0} ({1:N0} ticks)", string::format(date_format, date3), date3.ticks());
console::write_line("Difference between dates: {0} ({1:N0} ticks)", date3 - date1, date3.ticks() - date1.ticks());
}
};
startup_(program::main);
// This code produces the following output :
//
// Original date: 09/08/2014/16:00:00.0000000 (635457888000000000 ticks)
//
// Second date: 09/08/2014/16:00:30.0000000 (635457888300000000 ticks)
// Difference between dates: 00:00:30 (300000000 ticks)
//
// Third date: 09/09/2014/16:00:00.0000000 (635458752000000000 ticks)
// Difference between dates: 1.00:00:00 (864000000000 ticks)
Represents an instant in time, typically expressed as a date and time of day.
Definition date_time.hpp: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.hpp:175
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10