const d = new Date();
let month = d.getMonth(); // 5
const month = ["January","February","March","April","May","June","July","August","September","October","November","December"];
const d = new Date();
let name = month[d.getMonth()]; // June
new Date().getMonth();
const d = new Date();
d.getMonth();
Formating method if custom type is needed:
dateFormat(date: Date) {
var dateToFormat = new Date(date);
let day = dateToFormat.getDate();
let month = dateToFormat.getMonth() + 1;
let year = dateToFormat.getFullYear();
var dateFormatted = year + '/' + this.zeroPad(month) + '/' + this.zeroPad(day);
return dateFormatted;
}
//Adding a Zero to the single digit months and days
zeroPad(number: number) {
return ('0' + number).slice(-2);
}
let currentDate = new Date();
var dateString = this.dateFormat(currentDate) //2022/10/11
const d = new Date();
let month = d.getMonth(); // 5
const month = ["January","February","March","April","May","June","July","August","September","October","November","December"];
const d = new Date();
let name = month[d.getMonth()]; // June
new Date().getMonth();
const d = new Date();
d.getMonth();
Formating method if custom type is needed:
dateFormat(date: Date) {
var dateToFormat = new Date(date);
let day = dateToFormat.getDate();
let month = dateToFormat.getMonth() + 1;
let year = dateToFormat.getFullYear();
var dateFormatted = year + '/' + this.zeroPad(month) + '/' + this.zeroPad(day);
return dateFormatted;
}
//Adding a Zero to the single digit months and days
zeroPad(number: number) {
return ('0' + number).slice(-2);
}
let currentDate = new Date();
var dateString = this.dateFormat(currentDate) //2022/10/11