A Pen by hosein shurabi on CodePen.
Created
January 15, 2020 01:12
-
-
Save atxiii/afe28803e5d54aebb1b5090dea70cd67 to your computer and use it in GitHub Desktop.
Convert seconds to HH:MM:SS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const dateDiff = (fromdate, todate) => { | |
const diff = todate - fromdate; | |
const secondes = diff/1000 ; | |
const hour = (secondes / 3600) | |
const min = (secondes % 3600)/60; | |
const sec = (secondes % 3600 % 60); | |
const S = Math.abs(Math.floor( sec )) + '' ; | |
const M = Math.abs(Math.floor( min )) + ':' ; | |
const H = Math.abs(Math.floor( hour)) + ':' ; | |
return H+M+S; | |
} | |
//Set the two dates | |
const old = new Date(2020, 0, 15); | |
const today= new Date(); | |
console.log( dateDiff(old, today)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment