xxxxxxxxxx
const dayjs = require('dayjs');
let now = dayjs();
console.log(now.format());
xxxxxxxxxx
// You can use the "date-fns" library to format dates in JavaScript
// Install the library using npm
// npm install date-fns
// Import the necessary functions from the library
const { format } = require('date-fns');
// Format a given date according to a specified format string
const formattedDate = format(new Date(), 'yyyy-MM-dd HH:mm:ss');
console.log(formattedDate); // Output: 2022-12-31 23:59:59