date time format typescript 1

date time format typescript

import { DatePipe } from '@angular/common'
...
constructor(public datepipe: DatePipe){}
...
myFunction() {
 this.date=new Date();
 const start = this.datepipe.transform(this.date, 'yyyyMMdd\'T\'HHmmss.SSSZ');
}
....
in app.module.com
import { DatePipe } from '@angular/common'
...
providers: [DatePipe]

Here is what the above code is Doing:
1. Importing the DatePipe class from the @angular/common package.
2. Adding the DatePipe class to the providers array in the @NgModule decorator.
3. Injecting the DatePipe class into the constructor of the component.
4. Using the DatePipe class to transform the date object into a string.

Similar Posts