-1

I am new to angular and typescript. We a a date format that shows date in yyyy-mm but the way I have to show it on the UI is Feb 2018. I have used the split function I created var dateformat = (2018-02).split('-'). reverse ().join(' ') which gives me 02 2018, however I am not able to change 02 to read Feb Pls advice

HDJEMAI
  • 9,436
  • 46
  • 67
  • 93
piyol
  • 1
  • 1
  • Check out https://momentjs.com/ – Kevin Qian Mar 15 '18 at 00:00
  • In regard to javascript, a duplicate of [*Where can I find documentation on formatting a date in JavaScript?*](https://stackoverflow.com/questions/1056728/where-can-i-find-documentation-on-formatting-a-date-in-javascript) For Angular, it's a dupe of [*Angular 2 show current formatted date*](https://stackoverflow.com/questions/39515696/angular-2-show-current-formatted-date). – RobG Mar 15 '18 at 03:37

1 Answers1

2

Angular has a built-in pipe for dates: https://angular.io/api/common/DatePipe.

For more information on pipes, see https://angular.io/guide/pipes.

In your case:

import { Component } from '@angular/core';

@Component({
    selector: 'my-component',
    template: `Date {{ myDate | date:'LLL yyyy' }}`
})
export class MyComponent {
    myDate = new Date(2018, 2, 1);
}
brnovais
  • 101
  • 1
  • 7