Skip to content

Instantly share code, notes, and snippets.

@neoFelhz
Created April 25, 2017 02:13
Show Gist options
  • Save neoFelhz/0c098b6f53eb34015ee3af0c4d0b36be to your computer and use it in GitHub Desktop.
Save neoFelhz/0c098b6f53eb34015ee3af0c4d0b36be to your computer and use it in GitHub Desktop.
uptime for hexo-theme-material
<!-- 将文件放置在 _widget 目录下,然后在需要插入的地方调用该 ejs,并使用 id="htmer_time" 调用 -->
<script>
function secondToDate(second) {
if (!second) {
return 0;
}
var time = new Array(0, 0, 0, 0, 0);
if (second >= 365 * 24 * 3600) {
time[0] = parseInt(second / (365 * 24 * 3600));
second %= 365 * 24 * 3600;
}
if (second >= 24 * 3600) {
time[1] = parseInt(second / (24 * 3600));
second %= 24 * 3600;
}
if (second >= 3600) {
time[2] = parseInt(second / 3600);
second %= 3600;
}
if (second >= 60) {
time[3] = parseInt(second / 60);
second %= 60;
}
if (second > 0) {
time[4] = second;
}
return time;
}</script>
<script type="text/javascript" language="javascript">
function setTime() {
var create_time = Math.round(new Date(Date.UTC(2016, 08, 15, 20, 14, 19)).getTime() / 1000);
//由于月份的变量定义在 0-11,所以此处填入的月份需要减 1
var timestamp = Math.round((new Date().getTime() + 8 * 60 * 60 * 1000) / 1000);
currentTime = secondToDate((timestamp - create_time));
currentTimeHtml = currentTime[1] + ' 天 '
+ currentTime[2] + ' 时 ' + currentTime[3] + ' 分 ' + currentTime[4]
+ ' 秒';
document.getElementById("htmer_time").innerHTML = currentTimeHtml;
} setInterval(setTime, 1000);
</script>
<!-- End Uptime JS -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment