Skip to content

Instantly share code, notes, and snippets.

@HFreni
Created September 12, 2016 20:08
Show Gist options
  • Save HFreni/382e5b664cca0b9075974e879e874e57 to your computer and use it in GitHub Desktop.
Save HFreni/382e5b664cca0b9075974e879e874e57 to your computer and use it in GitHub Desktop.
const uptime = this.client.uptime;
const date = new Date(uptime);
const days = date.getUTCDate() - 1,
hours = date.getUTCHours(),
minutes = date.getUTCMinutes(),
seconds = date.getUTCSeconds();
// Initialize an array for the uptime.
let segments = [];
// Format the uptime string.
if (days > 0) segments.push(days + ' day' + ((days == 1) ? '' : 's'));
if (hours > 0) segments.push(hours + ' hour' + ((hours == 1) ? '' : 's'));
if (minutes > 0) segments.push(minutes + ' minute' + ((minutes == 1) ? '' : 's'));
if (seconds > 0) segments.push(seconds + ' second' + ((seconds == 1) ? '' : 's'));
const dateString = segments.join(', ');
// Return the uptime.
console.log("Today is: " + dateString);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment