May be another way using getTime()
You have to use ISO only. See this Stackoverflow Link
What is the "right" JSON date format?
import { DatePipe } from "@angular/common";
import { Component, VERSION } from "@angular/core";
@Component({
selector: "my-app",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"],
providers: [DatePipe]
})
export class AppComponent {
name = "Angular " + VERSION.major;
dataFormatted: string = "";
dateInMilliSecond: number;
dataISO: string = '';
constructor(protected datePipe: DatePipe) {}
ngOnInit() {
const today = new Date();
const datePipe = new DatePipe("en-IN");
this.dataFormatted = datePipe.transform(today, "dd/MM/yyyy, hh:mm a");
this.dateInMilliSecond = new Date().getTime();
this.dataISO = new Date().toISOString();
}
}
{{dataFormatted}}
<br/>
<br/>
In MilliSecond: {{dateInMilliSecond | date: 'dd/MM/yyyy, hh:mm a'}}
<br/>
<br/>
ISO Date : {{dataISO}}