3 回答
TA贡献1871条经验 获得超8个赞
您可以为此使用Angular 的日期管道
import { DatePipe } from "@angular/common";
@Component({
selector: "my-date",
templateUrl: "./date.component.html",
providers: [DatePipe] // Add DatePipe as Provider
})
export class DateComponent {
now: any = Date.now();
format: string = "medium"; // more formats are available inside the DatePipe Documentation
constructor(private datePipe: DatePipe) {} // Initialize DatePipe inside the constructor
get dateInGMT(): any {
// 1st parameter is the date
// 2nd parameter is the format
// 3rd parameter is the time zone
return this.datePipe.transform(this.now, this.format, "GMT");
}
get dateInCEST(): any {
return this.datePipe.transform(this.now, this.format, "CEST");
}
get dateInCustom(): any {
return this.datePipe.transform(this.now, this.format, "+0530");
}
}
你也可以这样做:
medium是一种格式,CST是时区,或者您可以提供您想要的任何值。
<pre>{{ now | date: 'medium' : 'CST' }}</pre>
TA贡献1795条经验 获得超7个赞
使用 momentjs 更改时区
var cst_time = moment.tz("2020-01-29 10:52:00", "America/Chicago"); // -6:00 var ist_time = cst_time .tz('Asia/Calcutta').format('MMMM Do YYYY, h:mm:ss a'); // +5:30
需要在此处更改您要将 IST 转换为 CST 的特定时区的区域
TA贡献1789条经验 获得超10个赞
var aestTime = new Date().toLocaleString("en-US", {
timeZone: "Australia/Brisbane"
});
console.log('AEST time: ' + (new Date(aestTime)).toISOString())
var asiaTime = new Date().toLocaleString("en-US", {
timeZone: "Asia/Shanghai"
});
console.log('Asia time: ' + (new Date(asiaTime)).toISOString())
var usaTime = new Date().toLocaleString("en-US", {
timeZone: "America/New_York"
});
console.log('USA time: ' + (new Date(usaTime)).toISOString())
var indiaTime = new Date().toLocaleString("en-US", {
timeZone: "Asia/Kolkata"
});
console.log('India time: ' + (new Date(indiaTime)).toISOString())
添加回答
举报