0
const getCurrentDate = () => {
  var date = new Date().getDate();
  var month = new Date().getMonth();

  return date + "-" + month;
};

I want to transform the number on the month var to letters f.e " 2-8 to 2 - August "

Sascha
  • 4,576
  • 3
  • 13
  • 34
Pau
  • 3
  • 2

1 Answers1

0

Create a const-array for the months and get the month-th element of it.

const MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];

const getCurrentDate = () => {
  var date = new Date().getDate();
  var month = new Date().getMonth();

  return date + "-" + MONTHS[month];
};

console.log(getCurrentDate());
Sascha
  • 4,576
  • 3
  • 13
  • 34
  • i fixed with : const getCurrentDate = () => { var options = { weekday: "long", month: "short", day: "numeric", }; var prnDt = new Date().toLocaleDateString("es", options); return prnDt; – Pau Sep 03 '20 at 12:06