Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

getmonth javascript

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
 
PREVIOUS NEXT
Tagged: #getmonth #javascript
ADD COMMENT
Topic
Name
4+3 =