JSFiddle - React, Tailwind, and code Playground
JavaScript
function date() {
let str = '';
const currentTime = new Date();
let year = currentTime.getFullYear().toString();
let month = currentTime.getMonth().toString();
let day = currentTime.getDate().toString();
let hours = currentTime.getHours().toString();
let minutes = currentTime.getMinutes().toString();
let seconds = currentTime.getSeconds().toString();
if ( month < 10) {
month = '0' + month;
}
if ( minutes < 10) {
minutes = '0' + minutes;
}
if (seconds < 10) {
seconds = '0' + seconds;
}
str += year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds + ' ';
alert(str);
}
date();