We are using java as Backend ,in which we use the ISO 8601. To pass the the same I need to convert the date into same format.
in java we use
DateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
similarly how to convert the date into the very same format in Angular/TypeScript
I'm attaching an Image for your reference for the date format. please see the image.

You need to use DatePipe in your component
app.component.ts
import { Component } from '@angular/core';
import { DatePipe } from '@angular/common';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ],
providers: [DatePipe]
})
export class AppComponent {
today;
constructor(
private datePipe:DatePipe
){
this.today = this.datePipe.transform( new Date(),'yyyy-MM-dd h:mm:ssZZZZZ');
}
}
For any other date-formats check here: https://angular.io/api/common/DatePipe
Working stackblitz example: https://stackblitz.com/edit/angular-datepipe-in-component-u8bzre?file=src/app/app.component.ts
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With