Created
November 1, 2015 01:55
-
-
Save hirokazumiyaji/8b331bf003f586f59633 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
"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