I am making an application in which I want user to submit date date is getting stored in database in this format 2003-06-01T00:00:00.000 00:00 I want to display it as 01/06/2003 or 1st June 2003 can any body help me how can I do this?
CodePudding user response:
You can use angular date pipe https://angular.io/api/common/DatePipe
<span>{{startDate | date:'MM/dd/yyyy'}}</span>
CodePudding user response:
I have created a small stackblitz for this. You can see date being formatted 4 different ways here:
- Plain old javascript date
- Formatted Javascript Date
- Using Angular Pipe in HTML file
- Using formateDate() function in component.ts file.
Please refer to this link: https://stackblitz.com/edit/angular-cue9h6?file=src/app/app.component.html
CodePudding user response:
You could use date pipe to format your standard ISO date in html template. Find the date object from your template, wrap the value in {{}}
and then add | date
pipe to format it. https://angular.io/api/common/DatePipe
<td>{{date}} </td>
<td>yyyy-MM-dd</td>
<td>{{date | localDate:'yyyy-MM-dd' }}</td>
<td>{{date | date:'yyyy-MM-dd'}}</td>
Here is a working example: https://stackblitz.com/edit/angular-local-date-pipe-bu2nxp?file=src/app/app.component.html