[script, webapp]时间本地时区格式化 (#35)
This commit is contained in:
20
web-app/src/app/shared/pipe/timezone.pipe.ts
Normal file
20
web-app/src/app/shared/pipe/timezone.pipe.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { formatDate, Location } from '@angular/common';
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
|
||||
@Pipe({
|
||||
name: 'timezone'
|
||||
})
|
||||
export class TimezonePipe implements PipeTransform {
|
||||
timeZone: string = 'Asia/Shanghai';
|
||||
|
||||
constructor() {
|
||||
this.timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
if (this.timeZone == undefined) {
|
||||
this.timeZone = 'Asia/Shanghai';
|
||||
}
|
||||
}
|
||||
|
||||
transform(value: any): string {
|
||||
return formatDate(value, 'YYYY-MM-DD HH:mm:ss', 'zh-cn');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user