0

I want to create a countdown script. I want to convert the date I created here into UTC.

var deadline = new Date("dec 31, 2019 21:00:00").getTime(); 

var x = setInterval(function() { 

var now = new Date().getTime(); 
var t = deadline - now; 
var days = Math.floor(t / (1000 * 60 * 60 * 24)); 
var hours = Math.floor((t%(1000 * 60 * 60 * 24))/(1000 * 60 * 60)); 
var minutes = Math.floor((t % (1000 * 60 * 60)) / (1000 * 60)); 
var seconds = Math.floor((t % (1000 * 60)) / 1000); 
document.getElementById("day").innerHTML =days ; 
document.getElementById("hour").innerHTML =hours; 
document.getElementById("minute").innerHTML = minutes; 
document.getElementById("second").innerHTML =seconds; 
if (t < 0) { 
        clearInterval(x); 
        document.getElementById("demo").innerHTML = "TIME UP"; 
        document.getElementById("day").innerHTML ='0'; 
        document.getElementById("hour").innerHTML ='0'; 
        document.getElementById("minute").innerHTML ='0' ; 
        document.getElementById("second").innerHTML = '0'; } 
}, 1000);
  • 1
    Does this answer your question? [How do you convert a JavaScript date to UTC?](https://stackoverflow.com/questions/948532/how-do-you-convert-a-javascript-date-to-utc) – Ahmed Gaafer Dec 31 '19 at 09:26
  • Side note: The string you're passing `new Date` is not in [the only format](https://tc39.es/ecma262/#sec-date-time-string-format) that `new Date` is specified to parse. That means you're falling back on "implementation-specific behavior or heuristics" which is unreliable. – T.J. Crowder Dec 31 '19 at 09:30

1 Answers1

0
var isoDate = new Date('yourdatehere').toISOString();

I got this answer from here

Ahmed Gaafer
  • 1,603
  • 9
  • 26