1 /******************************************************************** 2 * COPYRIGHT: 3 * Copyright (c) 1999-2003, International Business Machines Corporation and 4 * others. All Rights Reserved. 5 ********************************************************************/ 6 7 #include "unicode/unistr.h" 8 #include "unicode/calendar.h" 9 #include "unicode/datefmt.h" 10 #include "unicode/uclean.h" 11 #include <stdio.h> 12 #include <stdlib.h> 13 #include "util.h" 14 15 /** 16 * If the ID supplied to TimeZone is not a valid system ID, 17 * TimeZone::createTimeZone() will return a GMT zone object. In order 18 * to detect this error, we check the ID of the returned zone against 19 * the ID we requested. If they don't match, we fail with an error. 20 */ 21 TimeZone* createZone(const UnicodeString& id) { 22 UnicodeString str; 23 TimeZone* zone = TimeZone::createTimeZone(id); 24 if (zone->getID(str) != id) { 25 delete zone; 26 printf("Error: TimeZone::createTimeZone("); 27 uprintf(id); 28 printf(") returned zone with ID "); 29 uprintf(str); 30 printf("\n"); 31 exit(1); 32 } 33 return zone; 34 } 35 36 int main(int argc, char **argv) { 37 38 UErrorCode status = U_ZERO_ERROR; 39 UnicodeString str; 40 41 // The languages in which we will display the date 42 static char* LANGUAGE[] = { 43 "en", "de", "fr" 44 }; 45 static const int32_t N_LANGUAGE = sizeof(LANGUAGE)/sizeof(LANGUAGE[0]); 46 47 // The time zones in which we will display the time 48 static char* TIMEZONE[] = { 49 "America/Los_Angeles", 50 "America/New_York", 51 "Europe/Paris", 52 "Europe/Berlin" 53 }; 54 static const int32_t N_TIMEZONE = sizeof(TIMEZONE)/sizeof(TIMEZONE[0]); 55 56 for (int32_t i=0; i<N_LANGUAGE; ++i) { 57 Locale loc(LANGUAGE[i]); 58 59 // Display the formatted date string 60 printf("Date (%s)\n", LANGUAGE[i]); 61 } 62 63 printf("Exiting successfully\n"); 64 u_cleanup(); 65 return 0; 66 } 67