1 Star 0 Fork 5.2K

OpenHarmony-build / docs

forked from OpenHarmony / docs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
js-apis-intl.md 77.19 KB
一键复制 编辑 原始数据 按行查看 历史
zengyawen 提交于 2021-11-10 20:02 . add arkui

国际化(Intl)

说明: 从 API Version 6 开始支持。

导入模块

import intl from '@ohos.intl';

权限

Locale

属性

名称

参数类型

可读

可写

说明

language

string

与区域设置关联的语言

script

string

语言的书写方式

region

string

与区域设置相关的地区

baseName

string

Locale的基本核心信息

caseFirst

string

区域的整理规则是否考虑大小写

calendar

string

区域的日历信息

collation

string

区域的排序规则

hourCycle

string

区域的时制信息

numberingSystem

string

区域使用的数字系统

numeric

boolean

是否对数字字符具有特殊的排序规则处理

constructor

constructor(locale: string, options?:options)

创建区域对象

  • 参数:

    参数名

    类型

    必填

    说明

    locale

    string

    包含区域设置信息的字符串,包括语言以及可选的脚本和区域。

    options

    options

    用于创建区域对象的选项。

  • 示例:

    var locale = new Locale("zh-CN");

toString

toString(): string

将区域信息转换为字符串

  • 返回值:

    类型

    说明

    string

    字符串形式的区域信息

  • 示例:

    var locale = new Locale("zh-CN");
    locale.toString();

maximize

maximize(): Locale

最大化区域信息,若缺少脚本与地区信息,则补齐。

  • 返回值:

    类型

    说明

    Locale

    最大化后的区域对象

  • 示例:

    var locale = new Locale("zh-CN");
    locale.maximize();

minimize

minimize(): Locale

最小化区域信息,若包含脚本与地区信息,则去除。

  • 返回值:

    类型

    说明

    Locale

    最小化后的区域对象

  • 示例:

    var locale = new Locale("zh-CN");
    locale.minimize();

DateTimeFormat

constructor

constructor(locale: string, options?:DateTimeOptions)

创建时间日期格式化对象。

  • 参数:

    参数名

    类型

    必填

    说明

    locale

    string

    包含区域设置信息的字符串,包括语言以及可选的脚本和区域。

    options

    DateTimeOptions

    用于创建时间日期格式化的选项。

  • 示例:

    var datefmt= new DateTimeFormat("zh-CN", { dateStyle: 'full', timeStyle: 'medium' });

constructor

constructor(locales: Array<string>, options?:DateTimeOptions)

创建时间日期格式化对象。

  • 参数:

    参数名

    类型

    必填

    说明

    locales

    Array<string>

    包含区域设置信息的字符串的数组。

    options

    DateTimeOptions

    用于创建时间日期格式化的选项。

  • 示例:

    var datefmt= new DateTimeFormat(["ban", "zh"], { dateStyle: 'full', timeStyle: 'medium' });

format

format(date: Date): string;

格式化时间日期字符串。

  • 参数:

    参数名

    类型

    必填

    说明

    date

    Date

    时间日期对象。

  • 返回值:

    类型

    说明

    string

    格式化后的时间日期字符串

  • 示例:

    var date = new Date(2021, 11, 17, 3, 24, 0);
    var datefmt = new Intl.DateTimeFormat("en-GB");
    datefmt.format(date);

formatRange

formatRange(fromDate: Date, toDate: Date): string;

格式化时间日期段字符串。

  • 参数:

    参数名

    类型

    必填

    说明

    startDate

    Date

    起始的时间日期

    endDate

    Date

    结束的时间日期

  • 返回值:

    类型

    说明

    string

    格式化后的时间日期段字符串

  • 示例:

    var startDate = new Date(2021, 11, 17, 3, 24, 0);
    var endDate = new Date(2021, 11, 18, 3, 24, 0);
    var datefmt = new Intl.DateTimeFormat("en-GB");
    datefmt.formatRange(startDate, endDate);

resolvedOptions

resolvedOptions(): DateTimeOptions

获取DateTimeFormat 对象的格式化选项。

  • 返回值:

    类型

    说明

    DateTimeOptions

    DateTimeFormat 对象的格式化选项。

  • 示例:

    var datefmt = new Intl.DateTimeFormat("en-GB");
    datefmt.resolvedOptions();

NumberFormat

constructor

constructor(locale: string, options?:NumberOptions)

创建数字格式化对象。

参数:

参数名

类型

必填

说明

locale

string

包含区域设置信息的字符串,包括语言以及可选的脚本和区域。

options

NumberOptions

用于创建数字格式化的选项。

  • 示例:

    var numfmt = new Intl.NumberFormat("en-GB", {style:'decimal', notation:"scientific"});

constructor

constructor(locales: Array<string>, options?:NumberOptions)

创建数字格式化对象。

  • 参数:

    参数名

    类型

    必填

    说明

    locales

    Array<string>

    包含区域设置信息的字符串的数组。

    options

    NumberOptions

    用于创建数字格式化的选项。

  • 示例:

    var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"});

format

format(number: number): string;

格式化数字字符串。

  • 参数:

    参数名

    类型

    必填

    说明

    number

    number

    数字对象

  • 返回值:

    类型

    说明

    string

    格式化后的数字字符串

  • 示例:

    var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"});
    numfmt.format(1223);

resolvedOptions

resolvedOptions(): NumberOptions

获取NumberFormat 对象的格式化选项。

  • 返回值:

    类型

    说明

    NumberOptions

    NumberFormat 对象的格式化选项。

  • 示例:

    var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"});
    numfmt.resolvedOptions();

DateTimeOptions

表示时间日期格式化选项。

属性

名称

参数类型

可读

可写

说明

locale

string

区域参数

dateStyle

string

日期显示格式,取值范围:"long", "short", "medium", "full"

timeStyle

string

时间显示格式,取值范围:"long", "short", "medium", "full"

hourCycle

string

时制格式,取值范围:"h11", "h12", "h23", "h24".

timeZone

string

使用的时区(合法的IANA时区ID)

numberingSystem

string

数字系统

hour12

boolean

是否使用12小时制

weekday

string

工作日的显示格式,取值范围:"long", "short", "narrow"

era

string

时代的显示格式,取值范围:"long", "short", "narrow"

year

string

年份的显示格式,取值范围:"numeric", "2-digit"

month

string

月份的显示格式,取值范围:"numeric", "2-digit", "long", "short", "narrow"

day

string

日期的显示格式,取值范围:"numeric", "2-digit"

hour

string

小时的显示格式,取值范围:"numeric", "2-digit"

minute

string

分钟的显示格式,取值范围:"numeric", "2-digit"

second

string

秒钟的显示格式,取值范围:"numeric", "2-digit"

timeZoneName

string

时区名称的本地化表示

dayPeriod

string

时段的显示格式,取值范围:"long", "short", "narrow"

localeMatcher

string

要使用的区域匹配算法,取值范围:"lookup", "best fit"

formatMatcher

string

要使用的格式匹配算法,取值范围:"basic", "best fit"

NumberOptions

表示设备支持的能力。

属性

名称

参数类型

可读

可写

说明

locale

string

区域参数

currency

string

货币单位

currencySign

string

货币单位的符号显示

currencyDisplay

string

货币的显示方式,取值范围:"symbol", "narrowSymbol", "code", "name"

unit

string

单位

unitDisplay

string

单位的显示格式,取值范围:"long", "short", "medium"

signDisplay

string

数字符号的显示格式,取值范围:"auto", "never", "always", "expectZero"

compactDisplay

string

紧凑型的显示格式,取值范围:"long", "short"

notation

string

数字的格式化规格,取值范围:"standard", "scientific", "engineering", "compact"

localeMatcher

string

要使用的区域匹配算法,取值范围:"lookup", "best fit"

style

string

数字的显示格式,取值范围:"decimal", "currency", "percent", "unit"

numberingSystem

string

数字系统

useGrouping

boolean

是否分组显示

miniumumIntegerDigits

number

最少整数个数

miniumumFractionDigits

number

最少小数个数

maxiumumFractionDigits

number

最多小数个数

miniumumSignificantDigits

number

最少有效位个数

maxiumumSignificantDigits

number

最多有效位个数

1
https://gitee.com/openharmony-build/docs.git
git@gitee.com:openharmony-build/docs.git
openharmony-build
docs
docs
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891