Home > OS >  show date in correct format angular
show date in correct format angular

Time:02-10

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?

enter image description here

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:

  1. Plain old javascript date
  2. Formatted Javascript Date
  3. Using Angular Pipe in HTML file
  4. 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

  • Related