get time js code example
Example 1: javascript get time
var time = new Date();
time.getDate();
time.getDay();
time.getFullYear();
time.getHours();
time.getMinutes();
time.getSeconds();
time.getMilliseconds();
time.getTime();
time.toDateString();
time.toLocaleString();
time.toLocaleTimeString();
time.toLocaleDateString();
Example 2: javascript get current time
var today = new Date();
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
Example 3: 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 4: javascript get current time
var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
console.log(date.toLocaleTimeString('en-US'));
console.log(date.toLocaleTimeString('en-GB'));
Example 5: javascript get Time
var d=new Date();
d.getTime();
Example 6: get time in javascript
<a onclick="timeNow(test1)" href="#">SET TIME</a>
function timeNow(i) {
i.value = new Date()
}