JSFiddle - React, Tailwind, and code Playground

by Henry

JavaScript

const day = 30
const date = new Date(2023, 3, day + 1);

const dayFormat = new Intl.DateTimeFormat('en-US', { day: '2-digit' });
const monthFormat = new Intl.DateTimeFormat('en-US', { month: '2-digit' });
const yearFormat = new Intl.DateTimeFormat('en-US', { year: 'numeric' });

const parts = [
  yearFormat.format(date),
  monthFormat.format(date),
  dayFormat.format(date),
]

console.log(parts.join('-'))

// open the Console in the result pane