new date javascript get time code example
Example 1: javascript current date time
var today = new Date().toLocaleDateString(undefined, {
day: '2-digit',
month: '2-digit',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
})
Example 2: get time from date javascript
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
}
Example 3: javascript get Time
var d=new Date();
d.getTime();