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

Shows how to use xtd::date_time::to_string with format method.

#include <xtd/xtd>
class program {
public:
static auto main() {
auto date_value = date_time {2008, 6, 15, 21, 15, 07};
// Create an array of standard format strings.
auto standard_fmts = {"d", "D", "f", "F", "g", "G", "m", "o", "R", "s", "t", "T", "u", "U", "y"};
// Output date and time using each standard format string.
for (auto standard_fmt : standard_fmts)
console::write_line("{}: {}", standard_fmt, date_value.to_string(standard_fmt));
console::write_line();
// Create an array of some custom format strings.
auto custom_fmts = {"h:mm:ss.ff t", "d MMM yyyy", "HH:mm:ss.f", "dd MMM HH:mm:ss", "\\Mon\\t\\h\\: M", "HH:mm:ss.ffffzzz"};
// Output date and time using each custom format string.
for (auto custom_fmt : custom_fmts)
console::write_line("'{0}': {1}", custom_fmt, date_value.to_string(custom_fmt));
}
};
startup_(program::main);
// This code produces the following output :
//
// d: 6/15/2008
// D: Sunday, June 15, 2008
// f: Sunday, June 15, 2008 21:15
// F: Sunday, June 15, 2008 21:15:07
// g: 6/15/2008 21:15
// G: 6/15/2008 21:15:07
// m: June 15
// o: 2008-06-15T21:15:07.0000000Z
// R: Sun, 15 Jun 2008 21:15:07 GMT
// s: 2008-06-15T21:15:07
// t: 21:15
// T: 21:15:07
// u: 2008-06-15 21:15:07Z
// U: Sunday, June 15, 2008 21:15:07
// y: June 2008
//
// 'h:mm:ss.ff t': 9:15:07.00 P
// 'd MMM yyyy': 15 Jun 2008
// 'HH:mm:ss.f': 21:15:07.0
// 'dd MMM HH:mm:ss': 15 Jun 21:15:07
// '\Mon\t\h\: M': Month: 6
// 'HH:mm:ss.ffffzzz': 21:15:07.0000+02:00
#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:168