Skip to content

Instantly share code, notes, and snippets.

@hkirat
Created April 3, 2020 10:29
Show Gist options
  • Save hkirat/cb1694180c884c169aedef0ef8c1f10a to your computer and use it in GitHub Desktop.
Save hkirat/cb1694180c884c169aedef0ef8c1f10a to your computer and use it in GitHub Desktop.
const getTimeFromStamp = (n) => {
if(n<=0) {
return "Session Ongoing";
}
let day = parseInt(n / (24 * 3600));
n = n % (24 * 3600);
let hour = parseInt(n / 3600);
n %= 3600;
let minutes = parseInt(n / 60) ;
n %= 60;
let seconds = parseInt(n);
if(day) {
if(day!=1)
return `${day} days`
return `${day} day`
}
if(hour) {
if(hour!=1)
return `${hour} hours`
return `${hour} hour`
}
if(minutes) {
if(minutes!=1)
return `${minutes} minutes`
return `${minutes} minute `
}
return `${seconds} seconds`
//return `${day} day, ${hour}:${minutes}:${seconds}`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment