Local time

#include <x/tzfile.H>
#include <x/ymdhms.H>

time_t t=time(NULL);

x::ymdhms now(t, x::tzfile::base::local());

x::ymd now_date(now);
x::hms now_time(now);

A x::ymdhms combines x::ymd, x::hms, and a x::tzfile to specify a date and time expressed in a timezone. A number of constructors are available for creating x::ymdhms from alternate sources; such as a time_t calendar time value and a timezone; or an explicit x::ymd and x::hms objects, together with a timezone; or a C library tm structure.

std::string now_s=x::to_string(now.short_format());
std::string now_s=x::to_string(now.format("%d-%b-%Y %H:%M:%S %z"));

format() and short_format() methods return an intermediate object that can be converted by x::to_string() into a text string. This is done by instantiating a x::strftime object, and using it to format the x::ymdhms, accordingly. format() takes an optional date/time format string, which defaults to %a, %d %b %Y %H:%M:%S %z.

See the reference documentation for a more complete description of x::ymdhms. Note that this class incurs more overhead than the tm-related functions in the C library. Basic needs that can be satisfied by C library functions should use them. Use this class for complicated requirements that cannot be easily satisfied by the C library, such as pulling apart the date and time components, and/or date/time arithmetic.