You can utilize Angular's Date Pipe for it
Have attached a Stackblitz Demo for your reference
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");
}
}
You can also do it like this:
medium
is a format and CST
is the timezone or you can supply any values you want.
<pre>{{ now | date: 'medium' : 'CST' }}</pre>