• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Setting User Preferences (For System Applications Only)
2
3## Use Cases
4
5In addition to system locales and application preferred languages, the system supports setting of user preferences. Currently, the system supports two user preferences: whether to use local digits and whether to use the 12/24-hour format. User preference settings are saved to system locales and application preferred languages as part of the internationalization feature.
6
7## How to Develop
8
9For details about how to use the APIs, see [setUsingLocalDigit](../reference/apis-localization-kit/js-apis-i18n-sys.md#setusinglocaldigit9) and [set24HourClock](../reference/apis-localization-kit/js-apis-i18n-sys.md#set24hourclock9).
10
11
121. Import the **intl** module.
13   ```ts
14   import { i18n, intl } from '@kit.LocalizationKit';
15   import { BusinessError } from '@kit.BasicServicesKit';
16   ```
17
182. Obtain the preferred language of an application.
19   ```ts
20   // Obtain the preferred language of an application.
21   let appPreferredLanguage: string = i18n.System.getAppPreferredLanguage();
22   ```
23
243. Enable display of local digits on the application page.
25   ```ts
26   try {
27     i18n.System.setUsingLocalDigit(true); // Enable use of local digits.
28   } catch (error) {
29     let err: BusinessError = error as BusinessError;
30     console.error(`call System.setUsingLocalDigit failed, error code: ${err.code}, message: ${err.message}.`);
31   }
32   let date: Date = new Date(2023, 9, 25); // The date is 2023-10-25.
33   let appPreferredLanguage: string = 'ar';
34   let dateTimeFmt: intl.DateTimeFormat = new intl.DateTimeFormat(appPreferredLanguage);
35   let formattedTime: string = dateTimeFmt.format(date); // formattedTime = '٢٠٢٣/١٠/٢٥' (represented by localized numbers in Arabic)
36   ```
37
384. Set the 24-hour clock format.
39   ```ts
40   try {
41     i18n.System.set24HourClock (true); // Set the system time to the 24-hour clock.
42   } catch (error) {
43     let err: BusinessError = error as BusinessError;
44     console.error(`call System.set24HourClock failed, error code: ${err.code}, message: ${err.message}.`);
45   }
46   let date: Date = new Date(2023, 9, 25, 16, 48, 0); // The date and time is 2023-10-25 16:48:00.
47   let appPreferredLanguage: string = 'zh';
48   let dateTimeFmt: intl.DateTimeFormat = new intl.DateTimeFormat(appPreferredLanguage, { timeStyle: 'medium' });
49   let formattedTime: string = dateTimeFmt.format(date); // formattedTime = '16:48:00'
50   ```
51