Untitled

mail@pastecode.io avatar
unknown
plain_text
21 days ago
618 B
10
Indexable
Never
const currentDate = new Date();
const year = currentDate.getFullYear().toString().padStart(4, '0');
const month = (currentDate.getMonth() + 1).toString().padStart(2, '0'); // Month is zero-indexed
const day = currentDate.getDate().toString().padStart(2, '0');
const hours = currentDate.getHours().toString().padStart(2, '0');
const minutes = currentDate.getMinutes().toString().padStart(2, '0');
const seconds = currentDate.getSeconds().toString().padStart(2, '0');

const formattedDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
console.log(formattedDate); // Output: '2022-03-25 00:00:00'
Leave a Comment