Angular 10 getLocaleTimeFormat()函数
getLocaleTimeFormat是用来获取给定地区的本地化时间值格式的。
语法:
NgModule: getLocaleTimeFormat使用的模块是。
- CommonModule
步骤:
- 创建要使用的angular应用程序
- 在app.module.ts中导入LOCALE_ID,因为我们需要导入locale来使用getLocaleTimeFormat。
- 在app.component.ts中导入getLocaleTimeFormat和LOCALE_ID
- 注入LOCALE_ID作为一个公共变量。
- 在app.component.html中使用字符串插值显示局部变量
- 使用ng serve为angular应用程序提供服务以查看输出。
参数:
- locale:一个包含有规则的locale代码的字符串。
- width:可用于日期时间格式的字符串宽度。
返回:
- string: 一串本地化的格式化字符串。
示例 1:
输出:
示例 2:
输出: