Answers for "how to get the month using month number in js"

1

javascript get month name from number

export  const GetDatMonthFromDate=(dateSplit:any)=>{
    dateSplit = dateSplit.split('-');
    var monthShortNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
        "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
        ];
   var  months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

    const date = new Date(dateSplit[0], dateSplit[1], dateSplit[2]); // 2020-06-21
    return dateSplit[2]+' '+ monthShortNames[date.getMonth()];
}

GetDatMonthFromDate('2021-07-2');

//output = 2 sep;

// if you wanty full month then use months instead of monthShortNames on
// line number 9

//return dateSplit[2]+' '+ months[date.getMonth()];  output == 2 September
Posted by: Guest on August-31-2021
5

current month in javascript

// Find current month in JavaScript
const localDate = new Date();
const months = [
  'January',
  'February',
  'March',
  'April',
  'May',
  'June',
  'July',
  'August',
  'September',
  'October',
  'November',
  'December',
];
let currentMonth = months[localDate.getMonth()];
console.log(currentMonth);
Posted by: Guest on January-05-2021

Code answers related to "how to get the month using month number in js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language