
Date and Time Zone Examples
Calendar for Default Time Zone
This sample code is used to get a Calendar, which is based on the specified time zone ID in C++ and C.
C++
// get the supported ids for GMT-08:00 (Pacific Standard Time)
int32_t idsCount;
UErrorCode status = ZERO_ERROR;
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" << '\n';
// create a Pacific Standard Time time zone
SimpleTimeZone* pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, *(ids[0]));
// create a GregorianCalendar with the Pacific Daylight time zone
// and the current date and time
Calendar* calendar = new GregorianCalendar( pdt, status );
delete pdt;
delete[] ids;
delete calendar;
|
C
/* get the supported ids for GMT-08:00 (Pacific Standard Time) */
UErrorCode status = U_ZERO_ERROR;
UCalendar *calendar = 0;
int32_t idsCount = ucal_countAvailableTZIDs(-8 * 60 * 60 * 1000);
const Char* tz = ucal_getAvailableTZIDs( -8 * 60 * 60 * 1000, 0, &status);
/* if no ids were returned, something is wrong. get out. */
if (idsCount == 0) {
return;
}
/* begin output */
printf( "Current Time\n");
/* create a Calendar with the Pacific Daylight time zone */
/* and the current date and time */
status = U_ZERO_ERROR;
calendar = ucal_open( tz , u_strlen(tz), NULL, UCAL_GREGORIAN, &status)
ucal_close( calendar );
|
Copyright (c) 2000 - 2007 IBM and Others - PDF Version - Feedback: http://icu-project.org/contacts.html
User Guide for ICU v3.8 Generated 2007-09-14.
