]>
git.saurik.com Git - apple/icu.git/blob - icuSources/samples/datefmt/main.cpp
1 /********************************************************************
3 * Copyright (c) 1999-2003, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
7 #include "unicode/unistr.h"
8 #include "unicode/calendar.h"
9 #include "unicode/datefmt.h"
15 * If the ID supplied to TimeZone is not a valid system ID,
16 * TimeZone::createTimeZone() will return a GMT zone object. In order
17 * to detect this error, we check the ID of the returned zone against
18 * the ID we requested. If they don't match, we fail with an error.
20 TimeZone
* createZone(const UnicodeString
& id
) {
22 TimeZone
* zone
= TimeZone::createTimeZone(id
);
23 if (zone
->getID(str
) != id
) {
25 printf("Error: TimeZone::createTimeZone(");
27 printf(") returned zone with ID ");
35 int main(int argc
, char **argv
) {
40 UErrorCode status
= U_ZERO_ERROR
;
44 // The languages in which we will display the date
45 static char* LANGUAGE
[] = {
48 static const int32_t N_LANGUAGE
= sizeof(LANGUAGE
)/sizeof(LANGUAGE
[0]);
50 // The time zones in which we will display the time
51 static char* TIMEZONE
[] = {
52 "America/Los_Angeles",
57 static const int32_t N_TIMEZONE
= sizeof(TIMEZONE
)/sizeof(TIMEZONE
[0]);
60 cal
= Calendar::createInstance(status
);
61 check(status
, "Calendar::createInstance");
62 zone
= createZone("GMT"); // Create a GMT zone
63 cal
->adoptTimeZone(zone
);
65 cal
->set(1999, Calendar::JUNE
, 4);
66 date
= cal
->getTime(status
);
67 check(status
, "Calendar::getTime");
69 for (int32_t i
=0; i
<N_LANGUAGE
; ++i
) {
70 Locale
loc(LANGUAGE
[i
]);
72 // Create a formatter for DATE and TIME
73 fmt
= DateFormat::createDateTimeInstance(
74 DateFormat::kFull
, DateFormat::kFull
, loc
);
76 for (int32_t j
=0; j
<N_TIMEZONE
; ++j
) {
78 cal
->adoptTimeZone(createZone(TIMEZONE
[j
]));
79 fmt
->setCalendar(*cal
);
83 fmt
->format(date
, str
, status
);
85 // Display the formatted date string
86 printf("Date (%s, %s): ", LANGUAGE
[i
], TIMEZONE
[j
]);
94 printf("Exiting successfully\n");