Reputation: 1033
I'm currently working on a custom DatePicker in Angular4. I have managed to get a desired day (number, eg. 21), month (string, eg. "January") and a year (number, eg. 2018), passing them as a parameters to setData(year, month, day){} method. How can I assemble a date of dd/MMM/yyyy format from this data? Many thanks for help.
Upvotes: 0
Views: 772
Reputation: 1460
https://momentjs.com/ is a library you can use to manipulate the format of your dates. So if you have the day, month, and year you could use this function in moment.js to get the desired output:
setData(year, month, day) {
let date = moment().set({'year': year, 'month': month, 'day': day});
return date.format('L') // 01/24/2018
}
Look at https://momentjs.com/docs/#/displaying/format/ for all the formating options
Upvotes: 0