How to convert a date to milliseconds in JavaScript

3 Answers

0 votes
console.log(Date.parse("2020-03-23"));



/*
run:
   
1584921600000

*/

 



answered Mar 23, 2020 by avibootz
0 votes
const date = new Date("2020-03-23");
 
console.log(date.valueOf());
 
 
 
 
/*
run:
 
1584921600000
 
*/

 



answered Mar 23, 2020 by avibootz
edited 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 10:56:50 GMT+0200 (Israel Standard Time)"
1643446610495
 
*/

 



answered Jan 29, 2022 by avibootz

Related questions

1 answer 116 views
2 answers 164 views
1 answer 144 views
2 answers 151 views
1 answer 137 views
1 answer 160 views
...