Skip to content

Instantly share code, notes, and snippets.

@hirokazumiyaji
Created November 1, 2015 01:55
Show Gist options
  • Save hirokazumiyaji/8b331bf003f586f59633 to your computer and use it in GitHub Desktop.
Save hirokazumiyaji/8b331bf003f586f59633 to your computer and use it in GitHub Desktop.
"use strict";
function timediff(datetime, check_time=null, with_time=false) {
check_time = check_time || Math.floor(new Date().getTime() / 1000);
let timediff = check_time - datetime;
if (timediff === 0) {
return "now";
}
if (timediff < 60) {
return "";
}
if (timediff < 60 * 60) {
return "";
}
if (timediff < 60 * 60 * 24) {
return "";
}
let date = new Date(datetime * 1000);
if (with_time) {
return ``;
}
return new Date(datetime * 1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment