Q:

Write a JavaScript program to create tomorrow's date in a string representation

0

Write a JavaScript program to create tomorrow's date in a string representation.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

const tomorrow = (long = false) => {
  let t = new Date();
  t.setDate(t.getDate() + 1);
  const ret = `${t.getFullYear()}-${String(t.getMonth() + 1).padStart(2, '0')}-${String(
    t.getDate()
  ).padStart(2, '0')}`;
  return !long ? ret : `${ret}T00:00:00`;
};

console.log(tomorrow());
console.log(tomorrow(true));

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now