I am using the following function to get the Time using javascript:
function timeMil(){
var date = new Date();
var timeMil = date.getTime();
ret
I think you just have to divide it by 1000 milliseconds and you'll get time in seconds
Math.floor(date.getTime()/1000)
If brevity is ok, then:
function secondsSinceEpoch() {
return new Date/1000 | 0;
}
Where:
new Date
is equivalent to new Date()
| 0
truncates the decimal part of the result and is equivalent to Math.floor(new Date/1000)
(see What does |0 do in javascript).Using newer features, and allowing for a Date to be passed to the function, the code can be reduced to:
let getSecondsSinceEpoch = (x = new Date) => x/1000 | 0;
But I prefer function declarations as I think they're clearer.
You could divide by 1000 and use Math.floor()
on JavaScript.
Try dividing it by 1000, and use parseInt method.
const t = parseInt(Date.now()/1000);
console.log(t);