我想使用欧洲格式dd/MM/yyyy
显示日期,但使用DatePipe shortDate格式,它只能使用美国日期样式MM/dd/yyyy
显示.
我想使用欧洲格式dd/MM/yyyy
显示日期,但使用DatePipe shortDate格式,它只能使用美国日期样式MM/dd/yyyy
显示.
从Angular2RC6开始,您可以通过添加提供者在您的应用模块中设置默认区域设置:
@NgModule({
providers: [
{ provide: LOCALE_ID, useValue: "en-US" }, //replace "en-US" with your locale
//otherProviders...
]
})
货币/日期/数字管道应该会 Select 区域设置.LOCALE_ID为OpaqueToken,从Angular /核心导入.
import { LOCALE_ID } from '@angular/core';
对于更高级的用例,您可能希望从服务中 Select 区域设置.区域设置将在创建使用日期管道的组件时解析(一次):
{
provide: LOCALE_ID,
deps: [SettingsService], //some service handling global settings
useFactory: (settingsService) => settingsService.getLanguage() //returns locale string
}
希望对你有用.