在Angular中,可以使用DatePipe来格式化日期时间,并且可以通过设置timezone参数来控制是否进行时区转换。如果要显示不进行时区转换的日期时间,可以将timezone参数设置为'UTC'。
以下是一个示例代码:
在组件中引入DatePipe:
import { DatePipe } from '@angular/common';
在组件的构造函数中注入DatePipe:
constructor(private datePipe: DatePipe) {}
在模板中使用DatePipe来格式化日期时间:
{{ myDate | date:'yyyy-MM-dd HH:mm:ss':'UTC' }}
在上面的示例中,myDate是一个日期对象,date管道将日期对象格式化为指定的格式,并使用'UTC'时区参数来显示日期时间。
请注意,如果要使用DatePipe,您需要在模块文件中将CommonModule导入到imports数组中,并将DatePipe提供者添加到providers数组中:
import { CommonModule, DatePipe } from '@angular/common';
@NgModule({
imports: [CommonModule],
providers: [DatePipe],
// ...
})
export class YourModule { }
这样就可以在Angular应用中显示不进行时区转换的日期时间了。