GitHub 6219★

Convert a date to YYYY-MM-DD format

JavaScript version

// `date` is a `Date` object
const formatYmd = (date) => date.toISOString().slice(0, 10);

TypeScript version

const formatYmd = (date: Date): string => date.toISOString().slice(0, 10);

Example

formatYmd(new Date()); // 2020-05-06
Follow me on and to get more useful contents.