var date_time = new Date().toLocaleString();
console.log(date_time);
To get time and date you should use
new Date().toLocaleString(); >> "09/08/2014, 2:35:56 AM"
To get only the date you should use
new Date().toLocaleDateString(); >> "09/08/2014"
To get only the time you should use
new Date().toLocaleTimeString(); >> "2:35:56 AM"
const handleTime = (dataD) => {
let data= new Date(dataD)
let hrs = data.getHours()
let mins = data.getMinutes()
if(hrs<=9)
hrs = '0' + hrs
if(mins<10)
mins = '0' + mins
const postTime= hrs + ':' + mins
return postTime
}
<!DOCTYPE html>
<html>
<body>
<button type="button"
onclick="document.getElementById('display').innerHTML = Date()">
Click me to display Date and Time.</button>
<p id="display"></p>
</body>
</html>