Angular 角度:将UTC转换为本地日期时间

Angular 角度:将UTC转换为本地日期时间,angular,Angular,我想转换成2018-04-03T06:08:08-05:00 到 年月日HH:MM 如何在Angular 4.x+中实现这一点?与使用日期的vanilla javascript一样,使用getHours()、getMinutes()等等。下面是一个类似问题的参考,可能会有所帮助 尝试使用: 在html中: <p>Formatted Date: <b>{{ newdate | date:'MM.dd.yyyy HH:mm' }}</b> </p>

我想转换成2018-04-03T06:08:08-05:00

年月日HH:MM


如何在Angular 4.x+中实现这一点?

与使用日期的vanilla javascript一样,使用getHours()、getMinutes()等等。下面是一个类似问题的参考,可能会有所帮助

尝试使用:

在html中:

<p>Formatted  Date: <b>{{ newdate | date:'MM.dd.yyyy HH:mm' }}</b> </p>
输出:

Formatted Date: 04.03.2018 22:29

您需要查看以下内容:

正如链接中所述,您可以在组件中声明日期,例如:

export class DatePipeComponent {
  today = Date.now();
}
然后使用管道将其转换为所需格式:

{{today | date:'yyyy-MM-dd HH:mm a z':'+0900'}}

这些都是您可以使用时区的多种方式:-

{{currentDate | date:'short':'UTC +9:30 / +10:30'}}
{{currentDate | date:'short':'GMT'}}
{{currentDate | date:'short':'-0600'}}
{{currentDate | date:'short':'UTC+4'}}
日期格式如下所示:-

medium: Sep 9, 2019, 12:35:54 PM
long: September 9, 2019 at 12:35:54 PM GMT+5
full: Tuesday, September 9, 2019 at 12:35:54 PM GMT+05:30
shortDate: 09/3/19
mediumDate: Sep 9, 2019
longDate: September 9, 2019
fullDate: Tuesday, September 9, 2019
shortTime: 12:35 PM
mediumTime: 12:35:54 PM
longTime: 12:35:54 PM GMT+5
fullTime: 12:35:54 PM GMT+05:30
这些都是不同的时区示例:-

Alpha Time Zone 'UTC+1'
Arabia Standard Time 'UTC+3'
Central Standard Time 'UTC-6'
China Standard Time 'UTC+8'
Delta Time Zone 'UTC+4'
Greenwich Mean Time 'UTC+0'
Gulf Standard Time 'UTC+4'
Hawaii Standard Time 'UTC-10'
India Standard Time 'UTC+4'

使用角度日期管道Hi
newdate=newdate('2019-08-31T17:01:00');完整日期=新日期('2019-08-31T17:01:00-05:00')转换为
格式日期:{{newdate | Date:'ha'}带区域差异的完整日期{{fullDate | Date:'ha'}}

输出为:
格式日期:下午5点带区域差异的完整日期下午3点
有什么区别handling@Krish,使用矩js处理您的时区
Alpha Time Zone 'UTC+1'
Arabia Standard Time 'UTC+3'
Central Standard Time 'UTC-6'
China Standard Time 'UTC+8'
Delta Time Zone 'UTC+4'
Greenwich Mean Time 'UTC+0'
Gulf Standard Time 'UTC+4'
Hawaii Standard Time 'UTC-10'
India Standard Time 'UTC+4'