javascript get timestamp 10 digits code example
Example 1: js create timestamp with 10 digits
// Divide the 13-digit timestamp by 1000 and then round to get a 10-digit timestamp number
parseInt(+new Date()/1000);
// Convert the 13-digit timestamp to a string and intercept the first 10 digits to get a 10-digit timestamp string
(+new Date()).toString().substring(0,10); // intercept the 0-9th digits
(+new Date()).toString().substr(0,10); // intercept 10 digits from the 0th position
Example 2: get 13 digit timestamp javascript
// Define a time object dt, and then demonstrate various ways of converting dt to timestamp
var dt = new Date("2019-07-04 23:59:59.999");
// Write method one, accurate to the millisecond, get 13-bit timestamp 1562255999999
console.log(dt.getTime());
// Writing method two, accurate to the millisecond, get 13-bit timestamp 1562255999999
console.log(dt.valueOf());
// Writing method three, accurate to the millisecond, get 13-bit timestamp 1562255999999
console.log(Number(dt));
// Writing method four, accurate to the millisecond, get 13-bit timestamp 1562255999999
console.log(+dt);
// Write five, accurate to the second, get 13-digit timestamp 1562255999000, the last three digits are fixed as 000
console.log(Date.parse(dt));