How to convert a date to milliseconds in Node.js

3 Answers

0 votes
console.log(Date.parse("2022-01-23"));
 
 

 
/*
run:
    
1642896000000
 
*/

 



answered Jan 29, 2022 by avibootz
0 votes
const date = new Date("2022-01-19");
  
console.log(date.valueOf()); 
 
 


 
/*
run:
    
1642550400000
 
*/

 



answered Jan 29, 2022 by avibootz
0 votes
const d = new Date();
console.log(d.toString());
 
// milliseconds from midnight of January 1, 1970
const milliseconds = d.getTime();
 
console.log(milliseconds);
  
  
  
  
/*
run:
  
Sat Jan 29 2022 09:04:57 GMT+0000 (Coordinated Universal Time)
1643447097971
  
*/

 



answered Jan 29, 2022 by avibootz

Related questions

1 answer 151 views
1 answer 98 views
2 answers 168 views
2 answers 171 views
1 answer 109 views
1 answer 139 views
...