Coding Global Background
Coding Global

Get amount of seconds, minutes, hours and days between two dates

Archiviert 3 years ago
1
7 Nachrichten
0 Mitglieder
Erstellt 3 years ago
Aktualisiert 3 years ago
In Discord öffnen
J
Jordan
I'm looking to find the exact (or an approximate) amount of seconds, minutes & hours between an epoch time and the current date.

I was hoping to use momentjs for this because I thought it would help

Code:
let end   = moment(new Date().getTime())
let start = moment(cooldown[context]) //Proper epoch time

var duration = moment.duration(end.diff(start));
var between = {
  days:    duration.days(),
  hours:   duration.hours(),
  minutes: duration.asMinutes(),
  seconds: duration.asSeconds()
 }
 
console.log(between)


Console Output:
{
  days: 6,
  hours: 6,
  minutes: 27884526.431066666,
  seconds: 1673071585.864
}

Antworten (7)