time_zone |
For historical reasons, people equate the time of day with the position of the sun. For example, 1 p.m. is generally light, and 1 a.m. is usually dark.
To apply this rule of thumb around the world, the globe is split into time zones. England is in the time zone with the offset deemed to be zero. All other time zones are offset a positive or negative number, depending on how far west or east they are from England's time zone.
A positive offset means the time zone is behind the time in England and a negative offset means the time zone is ahead of the time in England. For example, Texas is in the Central Time Zone, which is offset +6 hours. This means Texas is 6 hours behind the time in England, so when it is 11 p.m. in Texas, it is 5 a.m. the next day in England.
To match people's schedules with the hours they customarily are awake, many time zones have daylight savings time rules that shift time forward (usually one hour) in spring and back by the same amount in autumn. These rules range from trivial to complex.
Because of time zones and daylight savings time, there are three common ways to specify time.
Every time zone has a unique abbreviation to describe it with and without daylight savings time. The following table lists examples of these abbreviations.
| Name | Abbreviation | Daylight Savings Abbreviation |
|---|---|---|
Every os_time_and_date
has an associated os_time_zone
. By default, the time zone for os_time_and_date is
the local time zone, which is deducted automatically when the program starts.
If the local time zone is determined to not be one of the predefined time zones
provided by os_time_zone, a generic time zone,
UTC+/-offset, will be provided with no rules for daylight savings time. For custom
time zones with DST rules, see Customizing time_zone.
Obtain the time zone for os_time_and_date using the
time_zone() function. Change the time zone using
the time_zone( const os_time_zone& tzone )
function.
The following example examines the characteristics of the local time zone. See Formats for more information on time and date formatting.
#include <iostream>
#include <ospace/time.h>
void
main()
{
os_time_toolkit initialize;
os_time_and_date::default_format( "%B %d %y (%Z), %H:%M" );
os_time_and_date now = os_time_and_date::now(); // Current time.
const os_time_zone& zone = now.time_zone();
cout << "local time zone = " << zone << endl;
cout << "name of zone = " << zone.name() << endl;
cout << "time zone offset = " << zone.offset() << endl;
if ( zone.dst_observed() )
{
cout << "name of zone w/ dst = " << zone.dst_name() << endl;
cout << "daylight savings in effect = " << now.is_dst() << endl;
}
cout << "local time and date = " << now << endl;
cout << "standard time = " << now.std_time() << endl;
cout << "standard date = " << now.std_date() << endl;
cout << "utc time = " << now.utc_time() << endl;
cout << "utc date = " << now.utc_date() << endl;
}
local time zone = os_time_zone( CST6, CDT5 )
name of zone = CST6
time zone offset = 21600 seconds
name of zone w/ dst = CDT5
daylight savings in effect = 0
local time and date = November 06 95 (CST6), 00:43
standard time = 00:43:22
standard date = 11/06/95
utc time = 06:43:22
utc date = 11/06/95
The time zone for an os_time_and_date
is specified during the time zone's construction.
In this case, the time and date parameters are treated as being local to the
specified time zone. If the time zone for an os_time_and_date
is changed using time_zone()
, the local time is adjusted according to the time offset between the old time
zone and the new time zone. The following example illustrates both setting the
time zone for an os_time_and_date and changing
the time zone using time_zone() .
#include <iostream>
#include <ospace/time.h>
void
main()
{
os_time_toolkit initialize;
os_time_and_date::default_format( "%B %d %y (%Z), %H:%M" );
os_time_and_date xmas
(
os_time( 0, 0 ),
os_date( os_date::december, 25, 1995 ),
os_time_zone::greenwich() // Specify time zone.
);
cout << "xmas in England = " << xmas << endl;
cout << "time zone in England = " << xmas.time_zone() << endl;
os_time_and_date now = os_time_and_date::now(); // Current time.
cout << "Local time = " << now << endl;
cout << "Local time zone = " << now.time_zone() << endl;
now.time_zone( os_time_zone::greenwich () ); // Change to GB time.
cout << "Time in England = " << now << endl;
cout << "Time zone in England = " << now.time_zone() << endl;
}
xmas in England = December 25 95 (GMT0), 00:00
time zone in England = os_time_zone( GMT0, BST-1 )
Local time = August 10 95 (CDT5), 11:45
Local time zone = os_time_zone( CST6, CDT5 )
Time in England = August 10 95 (BST-1), 17:45
Time zone in England = os_time_zone( GMT0, BST-1 )
Copyright©1994-2026 Recursion
Software LLC
All Rights Reserved - For use by licensed users only.