How to get ISO date without the milliseconds in JavaScript

2 Answers

0 votes
const date = new Date();

const ISOwithoutMs = date.toISOString().split('.')[0] + 'Z';

console.log(ISOwithoutMs); 

 
   
   
   
   
/*
run:
   
"2022-04-03T15:13:19Z"
   
*/

 



answered Apr 3, 2022 by avibootz
0 votes
const ISOdate = '2022-03-02T18:16:26.135Z';
 
const ISOdateWithoutMs = ISOdate.split('.')[0] + 'Z';
 
console.log(ISOdateWithoutMs); 
 
  
    
    
    
    
/*
run:
    
"2022-03-02T18:16:26Z"
    
*/

 



answered Apr 3, 2022 by avibootz
edited Apr 3, 2022 by avibootz

Related questions

2 answers 171 views
2 answers 172 views
2 answers 188 views
1 answer 150 views
1 answer 207 views
...