1# Calendar Setting
2
3## Use Cases
4
5Users in different locales use different calendars. To be specific, the Gregorian calendar is used in most locales, whereas calendars such as the lunar, Islamic, and Hebrew calendars are used in some other locales. What's more, the date and time on the calendar also vary according to the time zone and DST. Therefore, the system should allow users to choose calendars that comply with their local habits. This is made real with the complete set of internationalization (i18n) APIs provided by the [Calendar](../reference/apis-localization-kit/js-apis-i18n.md#calendar8) class. Besides setting the calendar type, date (year, month, and day), time zone, start date of a week, minimum number of days in the first week of a year, user can even determine whether a day is a weekend on the calendar and calculate the day difference between two dates. During application development, you can choose functions that suit your needs in a flexible manner.
6
7## How to Develop
8
9The following illustrates how to view the lunar calendar date corresponding to the Gregorian calendar date as an example to help you understand the usage of [Calendar](../reference/apis-localization-kit/js-apis-i18n.md#calendar8) APIs.
10
111. Import the **i18n** module.
12
13    ```ts
14     import { i18n } from '@kit.LocalizationKit';
15    ```
16
172. Configure the Gregorian calendar.
18
19    ```ts
20      let calendar : i18n.Calendar = i18n.getCalendar("zh-Hans", "gregory");
21      // Set the date for the Calendar object.
22      calendar.setTime(new Date(2022, 5, 13, 8, 0, 0));
23      calendar.setTime(10540800000);
24
25      // Set the year, month, day, hour, minute, and second for the Calendar object.
26      calendar.set(2022, 5, 13, 8, 0, 0);
27
28      // Set the time zone for the Calendar object.
29      calendar.setTimeZone("Asia/Shanghai");
30
31      // Obtain the time zone for the Calendar object.
32      let timezone: string = calendar.getTimeZone(); // Asia/Shanghai
33
34      // Obtain the start day of a week for the Calendar object.
35      let firstDayOfWeek : number = calendar.getFirstDayOfWeek(); // 1
36
37      // Set the start day of a week for the Calendar object.
38      calendar.setFirstDayOfWeek(1);
39
40      // Obtain the minimum number of days in the first week of a year for the Calendar object.
41      let minimalDaysInFirstWeek : number = calendar.getMinimalDaysInFirstWeek(); // 1
42
43      // Set the minimum number of days in the first week of a year for the Calendar object.
44      calendar.setMinimalDaysInFirstWeek(3);
45
46      // Obtain the value of the specified field in the Calendar object.
47      let value: number = calendar.get("year"); // 2022
48
49      // Obtain the localized name of the Calendar object.
50      let calendarName: string = calendar.getDisplayName("zh-Hans"); // Gregorian calendar
51
52      // Check whether a given date is a weekend for the Calendar object.
53      let isWeekend : boolean= calendar.isWeekend(new Date(2023, 9, 15)); // true
54
55      // Perform addition and subtraction operations on the specified field of the Calendar object.
56      calendar.set(2023, 10, 15);
57      calendar.add("date", 2);
58      calendar.get("date"); // 17
59
60      // Check the number of days between the Calendar object and the specified date.
61      calendar.compareDays(new Date(2023, 10, 15)); // -3
62    ```
63
643. Obtain the lunar calendar date corresponding to the Gregorian calendar date.
65
66    ```ts
67      let calendar : i18n.Calendar = i18n.getCalendar("zh-Hans", "chinese");
68      // Pass the Gregorian calendar information to the Calendar object.
69      calendar.setTime(new Date(2023, 6, 25, 8, 0, 0));
70      // Obtain the year, month, and day of the lunar calendar.
71      calendar.get("year"); // Year expressed in a heavenly stem and earthly branch, which is 40 in this example. The value ranges from 1 to 60.
72      calendar.get("month"); // The value 5 indicates June.
73      calendar.get ("date"); // Day, which is 8 in this example.
74    ```
75
76**Table 1** Supported calendar types
77
78| Type| Name|
79| -------- | -------- |
80| buddhist | Buddhist calendar|
81| chinese | Lunar calendar|
82| coptic | Coptic calendar|
83| ethiopic | Ethiopian calendar|
84| hebrew | Hebrew calendar|
85| gregory | Gregorian calendar|
86| indian | Indian calendar|
87| islamic_civil | Islamic calendar (civil epoch)|
88| islamic_tbla | Islamic calendar (tabular)|
89| islamic_umalqura | Islamic calendar (Umm al-Qura)|
90| japanese | Japanese calendar|
91| persian | Persian calendar|
92<!--RP1--><!--RP1End-->
93