Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
736 B
2
Indexable
Never
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);
Leave a Comment