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. The time and date on the calendar are calculated based on the calendar and may 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 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, and minimum number of days in the first week of a year, users 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 ```ts 13 import { i18n } from '@kit.LocalizationKit'; 14 ``` 15 162. Configure the Gregorian calendar. 17 ```ts 18 let calendar: i18n.Calendar = i18n.getCalendar('zh-Hans', 'gregory'); 19 // Set the date and time of the Calendar object to 2022.06.13 08:00:00. 20 calendar.setTime(new Date(2022, 5, 13, 8, 0, 0)); 21 calendar.setTime(10540800000); 22 23 // Set the date and time of the Calendar object to 2022.06.13 08:00:00. 24 calendar.set(2022, 5, 13, 8, 0, 0); 25 26 // Set the time zone for the Calendar object. 27 calendar.setTimeZone('Asia/Shanghai'); 28 29 // Obtain the time zone for the Calendar object. 30 let timezone: string = calendar.getTimeZone(); // timezone = 'Asia/Shanghai' 31 32 // Obtain the start day of a week for the Calendar object. 33 let firstDayOfWeek: number = calendar.getFirstDayOfWeek(); // firstDayOfWeek = 1 34 35 // Set the start day of a week for the Calendar object. 36 calendar.setFirstDayOfWeek(1); 37 38 // Obtain the minimum number of days in the first week of a year for the Calendar object. 39 let minimalDaysInFirstWeek: number = calendar.getMinimalDaysInFirstWeek(); // minimalDaysInFirstWeek = 1 40 41 // Set the minimum number of days in the first week of a year for the Calendar object. 42 calendar.setMinimalDaysInFirstWeek(3); 43 44 // Obtain the value of the specified field in the Calendar object. 45 let year: number = calendar.get('year'); // year = 2022 46 47 // Obtain the localized name of the Calendar object. 48 let calendarName: string = calendar.getDisplayName('zh-Hans'); // calendarName = 'Gregorian calendar' 49 50 // Check whether a given date is a weekend for the Calendar object. 51 let isWeekend: boolean = calendar.isWeekend(new Date(2023, 9, 15)); // isWeekend = true 52 53 // Perform addition and subtraction operations on the specified field of the Calendar object. 54 calendar.set(2023, 10, 15); 55 calendar.add('date', 2); 56 let day: number = calendar.get('date'); // day = 17 57 58 // Check the number of days between the Calendar object and the specified date. 59 let daysDifference: number = calendar.compareDays(new Date(2023, 10, 15)); // daysDifference = -3 60 ``` 61 623. Obtain the lunar calendar date corresponding to a Gregorian calendar date. 63 ```ts 64 let calendar: i18n.Calendar = i18n.getCalendar('zh-Hans', 'chinese'); 65 // Pass the Gregorian calendar date to the Calendar object, with the date and time being 2023.07.25 08:00:00. 66 calendar.setTime(new Date(2023, 6, 25, 8, 0, 0)); 67 // Obtain the year, month, and day of the lunar calendar. 68 let year: number = calendar.get('year'); // year = 40 indicates the age of the trunk branch. The value ranges from 1 to 60. 69 let month: number = calendar.get('month'); // month = 5 indicates June. 70 let day: number = calendar.get('date'); // day = 8 indicates the eighth day. 71 ``` 72 73**Table 1** List of supported calendars 74 75| Type| Name| 76| -------- | -------- | 77| buddhist | Buddhist calendar| 78| chinese | Lunar calendar| 79| coptic | Coptic calendar| 80| ethiopic | Ethiopian calendar| 81| hebrew | Hebrew calendar| 82| gregory | Gregorian calendar| 83| indian | Indian calendar| 84| islamic_civil | Islamic calendar (civil epoch)| 85| islamic_tbla | Islamic calendar (tabular)| 86| islamic_umalqura | Islamic calendar (Umm al-Qura)| 87| japanese | Japanese calendar| 88| persian | Persian calendar| 89<!--RP1--><!--RP1End--> 90