javascript - 在 angular 中将 UTC 时间转换为本地时间
我想在 Angular 中将这个 UTC 格式的日期转换为印度日期和时间格式
2019-02-18T17:31:19-05:00
我期望的格式是 DD/MM/YYYY HH:MM(例如:02/19/2019 04:01 AM)。有人能告诉我该怎么做吗..
答案#1
在原生 JavaScript 中实现这一点的一种方法是利用 Date.toLocaleString(),并通过将其设置为 timeZone 属性来转换为印度时区。
new Date('2019-02-18T17:31:19-05:00').toLocaleString("en-US", {timeZone: "Asia/Kolkata"});
console.log(new Date('2019-02-18T17:31:19-05:00').toLocaleString("en-US", {timeZone: "Asia/Kolkata"}));答案#2
根据本地规则格式化日期值。
{{ value_expression | date [ : format [ : timezone [ : locale ] ] ] }}来源:https://angular.io/api/common/DatePipe
