Concrete class which provides the standard calendar used by most of the world
Concrete class which provides the standard calendar used by most of the world.The standard (Gregorian) calendar has 2 eras, BC and AD.
This implementation handles a single discontinuity, which corresponds by default to the date the Gregorian calendar was originally instituted (October 15, 1582). Not all countries adopted the Gregorian calendar then, so this cutover date may be changed by the caller.
Prior to the institution of the Gregorian Calendar, New Year's Day was March 25. To avoid confusion, this Calendar always uses January 1. A manual adjustment may be made if desired for dates that are prior to the Gregorian changeover and which fall between January 1 and March 24.
Values calculated for the
WEEK_OF_YEAR
field range from 1 to 53. Week 1 for a year is the first week that contains at leastgetMinimalDaysInFirstWeek()
days from that year. It thus depends on the values ofgetMinimalDaysInFirstWeek()
,getFirstDayOfWeek()
, and the day of the week of January 1. Weeks between week 1 of one year and week 1 of the following year are numbered sequentially from 2 to 52 or 53 (as needed).For example, January 1, 1998 was a Thursday. If
getFirstDayOfWeek()
isMONDAY
andgetMinimalDaysInFirstWeek()
is 4 (these are the values reflecting ISO 8601 and many national standards), then week 1 of 1998 starts on December 29, 1997, and ends on January 4, 1998. If, however,getFirstDayOfWeek()
isSUNDAY
, then week 1 of 1998 starts on January 4, 1998, and ends on January 10, 1998; the first three days of 1998 then are part of week 53 of 1997.Example for using GregorianCalendar:
. // get the supported ids for GMT-08:00 (Pacific Standard Time) . int32_t idsCount; . const UnicodeString** ids = TimeZone::createAvailableIDs(-8 * 60 * 60 * 1000, idsCount); . // if no ids were returned, something is wrong. get out. . if (idsCount == 0) { . return; . } . . // begin output . cout << "Current Time" << endl; . . // create a Pacific Standard Time time zone . SimpleTimeZone* pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, *(ids[0])); . . // set up rules for daylight savings time . pdt->setStartRule(Calendar::APRIL, 1, Calendar::SUNDAY, 2 * 60 * 60 * 1000); . pdt->setEndRule(Calendar::OCTOBER, -1, Calendar::SUNDAY, 2 * 60 * 60 * 1000); . . // create a GregorianCalendar with the Pacific Daylight time zone . // and the current date and time . UErrorCode success = U_ZERO_ERROR; . Calendar* calendar = new GregorianCalendar( pdt, success ); . . // print out a bunch of interesting things . cout << "ERA: " << calendar->get( Calendar::ERA, success ) << endl; . cout << "YEAR: " << calendar->get( Calendar::YEAR, success ) << endl; . cout << "MONTH: " << calendar->get( Calendar::MONTH, success ) << endl; . cout << "WEEK_OF_YEAR: " << calendar->get( Calendar::WEEK_OF_YEAR, success ) << endl; . cout << "WEEK_OF_MONTH: " << calendar->get( Calendar::WEEK_OF_MONTH, success ) << endl; . cout << "DATE: " << calendar->get( Calendar::DATE, success ) << endl; . cout << "DAY_OF_MONTH: " << calendar->get( Calendar::DAY_OF_MONTH, success ) << endl; . cout << "DAY_OF_YEAR: " << calendar->get( Calendar::DAY_OF_YEAR, success ) << endl; . cout << "DAY_OF_WEEK: " << calendar->get( Calendar::DAY_OF_WEEK, success ) << endl; . cout << "DAY_OF_WEEK_IN_MONTH: " << calendar->get( Calendar::DAY_OF_WEEK_IN_MONTH, success ) << endl; . cout << "AM_PM: " << calendar->get( Calendar::AM_PM, success ) << endl; . cout << "HOUR: " << calendar->get( Calendar::HOUR, success ) << endl; . cout << "HOUR_OF_DAY: " << calendar->get( Calendar::HOUR_OF_DAY, success ) << endl; . cout << "MINUTE: " << calendar->get( Calendar::MINUTE, success ) << endl; . cout << "SECOND: " << calendar->get( Calendar::SECOND, success ) << endl; . cout << "MILLISECOND: " << calendar->get( Calendar::MILLISECOND, success ) << endl; . cout << "ZONE_OFFSET: " << (calendar->get( Calendar::ZONE_OFFSET, success )/(60*60*1000)) << endl; . cout << "DST_OFFSET: " << (calendar->get( Calendar::DST_OFFSET, success )/(60*60*1000)) << endl; . . cout << "Current Time, with hour reset to 3" << endl; . calendar->clear(Calendar::HOUR_OF_DAY); // so doesn't override . calendar->set(Calendar::HOUR, 3); . cout << "ERA: " << calendar->get( Calendar::ERA, success ) << endl; . cout << "YEAR: " << calendar->get( Calendar::YEAR, success ) << endl; . cout << "MONTH: " << calendar->get( Calendar::MONTH, success ) << endl; . cout << "WEEK_OF_YEAR: " << calendar->get( Calendar::WEEK_OF_YEAR, success ) << endl; . cout << "WEEK_OF_MONTH: " << calendar->get( Calendar::WEEK_OF_MONTH, success ) << endl; . cout << "DATE: " << calendar->get( Calendar::DATE, success ) << endl; . cout << "DAY_OF_MONTH: " << calendar->get( Calendar::DAY_OF_MONTH, success ) << endl; . cout << "DAY_OF_YEAR: " << calendar->get( Calendar::DAY_OF_YEAR, success ) << endl; . cout << "DAY_OF_WEEK: " << calendar->get( Calendar::DAY_OF_WEEK, success ) << endl; . cout << "DAY_OF_WEEK_IN_MONTH: " << calendar->get( Calendar::DAY_OF_WEEK_IN_MONTH, success ) << endl; . cout << "AM_PM: " << calendar->get( Calendar::AM_PM, success ) << endl; . cout << "HOUR: " << calendar->get( Calendar::HOUR, success ) << endl; . cout << "HOUR_OF_DAY: " << calendar->get( Calendar::HOUR_OF_DAY, success ) << endl; . cout << "MINUTE: " << calendar->get( Calendar::MINUTE, success ) << endl; . cout << "SECOND: " << calendar->get( Calendar::SECOND, success ) << endl; . cout << "MILLISECOND: " << calendar->get( Calendar::MILLISECOND, success ) << endl; . cout << "ZONE_OFFSET: " << (calendar->get( Calendar::ZONE_OFFSET, success )/(60*60*1000)) << endl; // in hours . cout << "DST_OFFSET: " << (calendar->get( Calendar::DST_OFFSET, success )/(60*60*1000)) << endl; // in hours . . delete[] ids; . delete calendar; // also deletes pdt .
alphabetic index hierarchy of classes
this page has been generated automatically by doc++
(c)opyright by Malte Zöckler, Roland Wunderling
contact: doc++@zib.de