1 /*************************************************************************
2 * Copyright (C) 2016 and later: Unicode, Inc. and others.
3 * License & terms of use: http://www.unicode.org/copyright.html#License
4 *************************************************************************
5 *************************************************************************
7 * Copyright (c) 1999-2003, International Business Machines Corporation and
8 * others. All Rights Reserved.
9 *************************************************************************/
11 #include "unicode/unistr.h"
12 #include "unicode/calendar.h"
13 #include "unicode/datefmt.h"
19 * If the ID supplied to TimeZone is not a valid system ID,
20 * TimeZone::createTimeZone() will return a GMT zone object. In order
21 * to detect this error, we check the ID of the returned zone against
22 * the ID we requested. If they don't match, we fail with an error.
24 TimeZone* createZone(const UnicodeString& id) {
26 TimeZone* zone = TimeZone::createTimeZone(id);
27 if (zone->getID(str) != id) {
29 printf("Error: TimeZone::createTimeZone(");
31 printf(") returned zone with ID ");
39 int main(int argc, char **argv) {
44 UErrorCode status = U_ZERO_ERROR;
48 // The languages in which we will display the date
49 static char* LANGUAGE[] = {
52 static const int32_t N_LANGUAGE = sizeof(LANGUAGE)/sizeof(LANGUAGE[0]);
54 // The time zones in which we will display the time
55 static char* TIMEZONE[] = {
56 "America/Los_Angeles",
61 static const int32_t N_TIMEZONE = sizeof(TIMEZONE)/sizeof(TIMEZONE[0]);
64 cal = Calendar::createInstance(status);
65 check(status, "Calendar::createInstance");
66 zone = createZone("GMT"); // Create a GMT zone
67 cal->adoptTimeZone(zone);
69 cal->set(1999, Calendar::JUNE, 4);
70 date = cal->getTime(status);
71 check(status, "Calendar::getTime");
73 for (int32_t i=0; i<N_LANGUAGE; ++i) {
74 Locale loc(LANGUAGE[i]);
76 // Create a formatter for DATE and TIME
77 fmt = DateFormat::createDateTimeInstance(
78 DateFormat::kFull, DateFormat::kFull, loc);
80 for (int32_t j=0; j<N_TIMEZONE; ++j) {
82 cal->adoptTimeZone(createZone(TIMEZONE[j]));
83 fmt->setCalendar(*cal);
87 fmt->format(date, str, status);
89 // Display the formatted date string
90 printf("Date (%s, %s): ", LANGUAGE[i], TIMEZONE[j]);
98 printf("Exiting successfully\n");