time_and_date |
An os_time_and_date
represents a single point
in time with microsecond accuracy between 00:00:00.000000 Jan 1, 4713 b.c. and
23:59:59.999999 Dec 31, 32766 a.d., and can be constructed from one of the
following.
os_time
and an os_datetm
structure (for backwards compatibility with C runtime library)os_time_period
The following example uses os_time_and_date
to calculate the number of
seconds a child named Drew has lived. The output of this example varies with
time.
#include <iostream>
#include <ospace/time.h>
void
main()
{
os_time_toolkit initialize;
os_time_and_date now = os_time_and_date::now();
cout << "now = " << now << endl;
os_time_and_date born // Drew's moment of birth.
(
os_time( 5, 22, 00 ),
os_date( os_date::june, 9, 1995 )
);
cout << "now = " << now << ", born = " << born << endl;
cout << "born.date() = " << born.date() << endl;
cout << "born.time() = " << born.time() << endl;
cout << "seconds alive = " << (now - born).to_seconds() << endl;
os_time_and_date tomorrow = now + os_time_period(1, 0, 0, 0, 0 );
cout << "same time tomorrow = " << tomorrow << endl;
#if defined OS_WIN32
setlocale(LC_ALL, "Chinese");
os_time_and_date::initialize_statics(Utf8);
os_time_and_date now1 = os_time_and_date::now();
cout << "now = " << now1 << endl;
cout << "tz = " << now1.time_zone() << endl;
os_time_and_date born1
(
os_time( 5, 22, 00 ),
os_date( os_date::june, 8, 1995 )
);
cout << "now = " << now1 << ", born = " << born1 << endl;
cout << "born.date() = " << born1.date() << endl;
cout << "born.time() = " << born1.time() << endl;
OS_STD os_string bmonth1 = os_date::month_name( born1.date().month () );
OS_STD os_wstring wbmonth1 = widen(bmonth1);
OS_STD os_string bmonth_abbr1 = os_date::month_abbreviation( born1.date().month () );
OS_STD os_wstring wbmonth_abbr1 = widen(bmonth_abbr1);
OS_STD_IO wcout << L"born month with locale = " << wbmonth1 << endl;
OS_STD os_string bweekday1 = os_date::weekday_name( born1.date().weekday () );
OS_STD os_wstring wbweekday1 = widen(bweekday1);
OS_STD_IO wcout << L"born weekday with locale = " << wbweekday1 << endl << endl;
cout << "seconds alive = " << (now1 - born1).to_seconds() << endl;
os_time_and_date same_time_tomorrow1 = now1 + os_time_period( 1, 0, 0, 0, 0 );
cout << "same time tomorrow = " << same_time_tomorrow1 << endl;
#endif
}
now = 08/30/2013 15:24:57.878000
tz = os_time_zone( CST6, CDT5 )
now = 08/30/2013 15:24:57.878000, born = 06/ 9/1995 05:22:00.000000
born.date() = 06/ 9/1995
born.time() = 05:22:00.000000
seconds alive = 575200977
same time tomorrow = 08/31/2013 15:24:57.878000
now = 2013/08/30 15:24:57.896000
tz = os_time_zone( CST6, CDT5 )
now = 2013/08/30 15:24:57.896000, born = 1995/06/ 8 05:22:00.000000
born.date() = 1995/06/ 8
born.time() = 05:22:00.000000
born month with locale = ??
born weekday with locale = ???
seconds alive = 575287377
same time tomorrow = 2013/08/31 15:24:57.896000
Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.