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

◆ date()

date_time xtd::date_time::date ( ) const
noexcept

Gets the date component of this instance.

Returns
A new object with the same date as this instance, and the time value set to 12:00:00 midnight (00:00:00).
Examples
The following example uses the xtd::date_time::date property to extract the date component of a xtd::date_time value with its time component set to zero (or 0:00:00, or midnight). It also illustrates that, depending on the format string used when displaying the xtd::date_time value, the time component can continue to appear in formatted output.
#include <xtd/console>
#include <xtd/date_time>
#include <xtd/startup>
using namespace xtd;
class program {
public:
static auto main() {
auto date1 = date_time {2008, 6, 1, 7, 47, 0};
console::write_line(date1.to_string());
// Get date-only portion of date, without its time.
auto date_only = date1.date();
// Display date using short date string.
console::write_line(date_only.to_string("d"));
// Display date using 24-hour clock.
console::write_line(date_only.to_string("g"));
console::write_line(date_only.to_string("u"));
}
};
startup_(program::main);
// This code produces the following output :
// Sun Jun 1 07:47:00 2008
// 06/01/2008
// Sun Jun 1 00:00:00 2008
// 2008-06-01 00:00:00
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
Remarks
The value of the xtd::date_time::kind property of the returned xtd::date_time value is the same as that of the current instance.
Because the xtd::date_time type represents both dates and times in a single type, it is important to avoid misinterpreting a date returned by the xtd::date property as a date and time.