Untitled
unknown
plain_text
2 years ago
736 B
9
Indexable
function getCurrentDateTime() {
const now = new Date();
const year = now.getFullYear();
const month = ('0' + (now.getMonth() + 1)).slice(-2); // Adding leading zero if month < 10
const day = ('0' + now.getDate()).slice(-2); // Adding leading zero if day < 10
const hours = ('0' + now.getHours()).slice(-2); // Adding leading zero if hours < 10
const minutes = ('0' + now.getMinutes()).slice(-2); // Adding leading zero if minutes < 10
const seconds = ('0' + now.getSeconds()).slice(-2); // Adding leading zero if seconds < 10
const formattedDateTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
return formattedDateTime;
}
const currentDateTime = getCurrentDateTime();
console.log(currentDateTime);
Editor is loading...
Leave a Comment