How to convert a date to milliseconds in TypeScript

3 Answers

0 votes
console.log(Date.parse("2021-03-22"));
 
 
 
/*
run:
    
1616371200000 
 
*/

 



answered Jan 29, 2022 by avibootz
0 votes
const date = new Date("2021-03-22");
 
console.log(date.valueOf());
 
 
 
 
/*
run:
 
1616371200000 
 
*/

 



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 11:01:07 GMT+0200 (Israel Standard Time)" 
1643446867003 
  
*/

 



answered Jan 29, 2022 by avibootz

Related questions

...