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 "

2

1 Answer 1

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());

Sign up to request clarification or add additional context in comments.

1 Comment

i fixed with : const getCurrentDate = () => { var options = { weekday: "long", month: "short", day: "numeric", }; var prnDt = new Date().toLocaleDateString("es", options); return prnDt;

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.