]>
git.saurik.com Git - apple/icu.git/blob - icuSources/samples/datecal/cal.cpp
2 *******************************************************************************
4 * © 2016 and later: Unicode, Inc. and others.
5 * License & terms of use: http://www.unicode.org/copyright.html#License
7 *******************************************************************************
8 *******************************************************************************
10 * Copyright (C) 2002-2012, International Business Machines
11 * Corporation and others. All Rights Reserved.
13 *******************************************************************************
16 #include "unicode/calendar.h"
17 #include "unicode/gregocal.h"
20 extern "C" void c_main();
24 UErrorCode status
= U_ZERO_ERROR
;
26 GregorianCalendar
* gc
= new GregorianCalendar(status
);
27 if (U_FAILURE(status
)) {
28 puts("Couldn't create GregorianCalendar");
32 gc
->set(2000, UCAL_FEBRUARY
, 26);
33 gc
->set(UCAL_HOUR_OF_DAY
, 23);
34 gc
->set(UCAL_MINUTE
, 0);
35 gc
->set(UCAL_SECOND
, 0);
36 gc
->set(UCAL_MILLISECOND
, 0);
37 /* Iterate through the days and print it out. */
38 for (int32_t i
= 0; i
< 30; i
++) {
39 /* print out the date. */
40 /* You should use the DateFormat to properly format it */
41 printf("year: %d, month: %d (%d in the implementation), day: %d\n",
42 gc
->get(UCAL_YEAR
, status
),
43 gc
->get(UCAL_MONTH
, status
) + 1,
44 gc
->get(UCAL_MONTH
, status
),
45 gc
->get(UCAL_DATE
, status
));
46 if (U_FAILURE(status
))
48 puts("Calendar::get failed");
51 /* Add a day to the date */
52 gc
->add(UCAL_DATE
, 1, status
);
53 if (U_FAILURE(status
)) {
54 puts("Calendar::add failed");
62 /* Creating and using text boundaries */
65 puts("Date-Calendar sample program");