How to convert a month number to name in TypeScript

2 Answers

0 votes
function getMonthName(month : number){
  const date = new Date();
  date.setMonth(month - 1);
  const monthName = date.toLocaleString('en-us', { month: 'long' });    
    
  return monthName;
}
  
console.log(getMonthName(3)); 
  
  
  
  
/*
run:
  
"March" 
  
*/

 



answered Mar 6, 2022 by avibootz
0 votes
function getMonthName(month : number){
  const date = new Date();
  date.setMonth(month - 1);
  const monthName = date.toLocaleString('en-us', { month: 'short' });    
    
  return monthName;
}
  
console.log(getMonthName(3)); 
  
  
  
/*
run:
  
"Mar" 
  
*/

 



answered Mar 6, 2022 by avibootz

Related questions

...