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

◆ sprintf()

static xtd::ustring xtd::date_time::sprintf ( const ustring format,
const date_time value 
)
static

Returns a xtd::ustring that represents the current xtd::date_time.

Parameters
formatFormat-control String.
valueThe xtd::date_time object to format.
Returns
A xtd::ustring that represents the current xtd::date_time.
Examples
The foloowwing example shows how to use xtd::date_time::sprintf with differentt formats.
#include <xtd/console>
#include <xtd/date_time>
#include <xtd/startup>
using namespace xtd;
class program {
public:
static auto main() {
auto date1 = date_time {2008, 4, 1, 18, 7, 5, 16};
console::write_line(date_time::sprintf("%a", date1)); // Tue
console::write_line(date_time::sprintf("%A", date1)); // Tuesday
console::write_line(date_time::sprintf("%b", date1)); // Apr
console::write_line(date_time::sprintf("%B", date1)); // April
console::write_line(date_time::sprintf("%c", date1)); // Tue Apr 1 18:07:05 2008
console::write_line(date_time::sprintf("%C", date1)); // 20
console::write_line(date_time::sprintf("%d", date1)); // 01
console::write_line(date_time::sprintf("%D", date1)); // 04/01/08
console::write_line(date_time::sprintf("%e", date1)); // 1
console::write_line(date_time::sprintf("%Ec", date1)); // Tue Apr 1 18:07:05 2008
console::write_line(date_time::sprintf("%EC", date1)); // 20
console::write_line(date_time::sprintf("%Ex", date1)); // 04/01/08
console::write_line(date_time::sprintf("%EX", date1)); // 18:07:05
console::write_line(date_time::sprintf("%Ey", date1)); // 08
console::write_line(date_time::sprintf("%EY", date1)); // 2008
console::write_line(date_time::sprintf("%F", date1)); // 2008-04-01
console::write_line(date_time::sprintf("%g", date1)); // 08
console::write_line(date_time::sprintf("%G", date1)); // 2008
console::write_line(date_time::sprintf("%h", date1)); // Apr
console::write_line(date_time::sprintf("%H", date1)); // 18
console::write_line(date_time::sprintf("%I", date1)); // 06
console::write_line(date_time::sprintf("%j", date1)); // 093
console::write_line(date_time::sprintf("%m", date1)); // 04
console::write_line(date_time::sprintf("%M", date1)); // 07
console::write_line(date_time::sprintf("%p", date1)); // PM
console::write_line(date_time::sprintf("%r", date1)); // 06:07:05 PM
console::write_line(date_time::sprintf("%R", date1)); // 18:07
console::write_line(date_time::sprintf("%S", date1)); // 05
console::write_line(date_time::sprintf("%T", date1)); // 18:07:05
console::write_line(date_time::sprintf("%u", date1)); // 2
console::write_line(date_time::sprintf("%U", date1)); // 13
console::write_line(date_time::sprintf("%V", date1)); // 14
console::write_line(date_time::sprintf("%w", date1)); // 2
console::write_line(date_time::sprintf("%W", date1)); // 14
console::write_line(date_time::sprintf("%x", date1)); // 04/01/08
console::write_line(date_time::sprintf("%X", date1)); // 18:07:05
console::write_line(date_time::sprintf("%y", date1)); // 08
console::write_line(date_time::sprintf("%Y", date1)); // 2008
console::write_line(date_time::sprintf("%z", date1)); // +0100
console::write_line(date_time::sprintf("%Z", date1)); // CET
console::write_line(date_time::sprintf("%Od", date1)); // 01
console::write_line(date_time::sprintf("%Oe", date1)); // 1
console::write_line(date_time::sprintf("%OH", date1)); // 18
console::write_line(date_time::sprintf("%OI", date1)); // 06
console::write_line(date_time::sprintf("%Om", date1)); // 04
console::write_line(date_time::sprintf("%OM", date1)); // 07
console::write_line(date_time::sprintf("%OS", date1)); // 05
console::write_line(date_time::sprintf("%Ou", date1)); // 2
console::write_line(date_time::sprintf("%OU", date1)); // 13
console::write_line(date_time::sprintf("%OV", date1)); // 14
console::write_line(date_time::sprintf("%Ow", date1)); // 2
console::write_line(date_time::sprintf("%OW", date1)); // 14
console::write_line(date_time::sprintf("%Oy", date1)); // 08
}
};
startup_(program::main);
// This code produces the following output :
//
// Tue
// Tuesday
// Apr
// April
// Tue Apr 1 18:07:05 2008
// 20
// 01
// 04/01/08
// 1
// Tue Apr 1 18:07:05 2008
// 20
// 04/01/08
// 18:07:05
// 08
// 2008
// 2008-04-01
// 08
// 2008
// Apr
// 18
// 06
// 093
// 04
// 07
// PM
// 06:07:05 PM
// 18:07
// 05
// 18:07:05
// 2
// 13
// 14
// 2
// 14
// 04/01/08
// 18:07:05
// 08
// 2008
// +0100
// CET
// 01
// 1
// 18
// 06
// 04
// 07
// 05
// 2
// 13
// 14
// 2
// 14
// 08
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 formatting codes for sprintf are listed below:
Format Print
%a writes abbreviated weekday name, e.g. Fri (locale dependent).
%A writes full weekday name, e.g. Friday (locale dependent).
%b writes abbreviated month name, e.g. Oct (locale dependent)
%B writes full month name, e.g. October (locale dependent).
%c  writes standard date and time string, e.g. Sun Oct 17 04:41:13 2010 (locale dependent).
%C writes first 2 digits of year as a decimal number (range [00,99]).
%d writes day of the month as a decimal number (range [01,31]).
%D equivalent to "%m/%d/%y".
%e  writes day of the month as a decimal number (range [1,31]).
%Ec writes alternative date and time string, e.g. using 平成23年 (year Heisei 23) instead of 2011年 (year 2011) in ja_JP locale.
%EC Writes name of the base year (period) in the locale's alternative representation, e.g. 平成 (Heisei era) in ja_JP
%Ex  writes alternative date representation, e.g. using 平成23年 (year Heisei 23) instead of 2011年 (year 2011) in ja_JP locale.
%EX writes alternative time representation (locale dependent).
%Ey writes year as offset from locale's alternative calendar period EC.
%EY writes year in the alternative representation, e.g.平成23年 (year Heisei 23) instead of 2011年 (year 2011) in ja_JP locale.
%F equivalent to "%Y-%m-%d" (the ISO 8601 date format).
%g  writes last 2 digits of ISO 8601 week-based year, i.e. the year that contains the specified week (range [00,99]).
%G  writes ISO 8601 week-based year, i.e. the year that contains the specified week.
%h synonym of b.
%H writes hour as a decimal number, 24 hour clock (range [00-23]).
%I writes hour as a decimal number, 12 hour clock (range [01,12]).
%j writes day of the year as a decimal number (range [001,366]).
%m writes month as a decimal number (range [01,12]).
%M writes minute as a decimal number (range [00,59]).
%Od writes zero-based day of the month using the alternative numeric system, e.g 二十七 instead of 27 in ja_JP locale.
%Oe writes one-based day of the month using the alternative numeric system, e.g. 二十七 instead of 27 in ja_JP locale.
%OH writes hour from 24-hour clock using the alternative numeric system, e.g. 十八 instead of 18 in ja_JP locale.
%OI writes hour from 12-hour clock using the alternative numeric system, e.g. 六 instead of 06 in ja_JP locale.
%Om writes month using the alternative numeric system, e.g. 十二 instead of 12 in ja_JP locale.
%OM writes minute using the alternative numeric system, e.g. 二十五 instead of 25 in ja_JP locale.
%OS  writes second using the alternative numeric system, e.g. 二十四 instead of 24 in ja_JP locale.
%Ou writes weekday, where Monday is 1, using the alternative numeric system, e.g. 二 instead of 2 in ja_JP locale.
%OU writes week of the year, as by U, using the alternative numeric system, e.g. 五十二 instead of 52 in ja_JP locale.
%OV  writes week of the year, as by V, using the alternative numeric system, e.g. 五十二 instead of 52 in ja_JP locale.
%Ow writes weekday, where Sunday is 0, using the alternative numeric system, e.g. 二 instead of 2 in ja_JP locale.
%OW writes week of the year, as by W, using the alternative numeric system, e.g. 五十二 instead of 52 in ja_JP locale.
%Oy writes last 2 digits of year using the alternative numeric system, e.g. 十一 instead of 11 in ja_JP locale.
%p writes localized a.m. or p.m. (locale dependent).
%r  writes localized 12-hour clock time (locale dependent).
%R  equivalent to "%H:%M".
%S writes second as a decimal number (range [00,60]).
%T  equivalent to "%H:%M:%S" (the ISO 8601 time format)
%u writes weekday as a decimal number, where Monday is 1 (ISO 8601 format) (range [1-7]).
%U writes week of the year as a decimal number (Sunday is the first day of the week) (range [00,53]).
%V  writes ISO 8601 week of the year (range [01,53]).
%w writes weekday as a decimal number, where Sunday is 0 (range [0-6]).
%W writes week of the year as a decimal number (Monday is the first day of the week) (range [00,53]).
%x writes localized date representation (locale dependent).
%X writes localized time representation, e.g. 18:40:20 or 6:40:20 PM (locale dependent).
%y writes last 2 digits of year as a decimal number (range [00,99]).
%Y writes year as a decimal number, e.g. 2017.
%z writes offset from UTC in the ISO 8601 format (e.g. -0430), or no characters if the time zone information is not available.
%Z writes locale-dependent time zone name or abbreviation, or no characters if the time zone information is not available.
%% writes literal %. The full conversion specification must be %%.
%n writes newline character.
%t writes horizontal tab character.
See std::put_time for more information.