How to convert a number into date format

i have the variable :

this.dated = 217

i want to convert this variable into date format and render it in page.
how to do ?

What’s the format of ‘217’ ? DDM ?

Use datetime for display, or else moment.js

i need to display the date as 05-august

How is 217 = 05-Aug ?

count the total number of days
jan - 31 days
feb - 28 days
mar - 31 days
april - 30 days
may - 31 days
june - 30 days
july - 31 days
august - 05th day

so it is totally 217th day of the year , how to convert this into date format ?

  1. Install ngx-moment.
  2. Add moment in your component:
import * as moment from 'moment';
  1. Do the conversion:
let dayOfYear = 217;
let date = moment("2018-01-01").add(dayOfYear, 'd');
console.log(date.format('do-MMMM'));

Moment add docs.
Moment format docs.

Take a look at moment.js perhaps they have a day of year function…

Assuming you have already seen the answers above.

I think this,
let date = moment('217', 'DDD').format('do-MMMM')
will also work.

Write a directive to use pipe and format in html directly

this shows the next date from the current date.
it displays 06th august

Use @elvis_gn’s solution.

it shows 0th-august already

thanks its working on
let date = moment(‘217’, ‘DDD’).format(‘DD-MMMM’)