Created
March 1, 2018 10:23
-
-
Save maicong/2e70c053cb5ee3a864b6ed6680bcf72a 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>时间如白驹过隙</title> | |
</head> | |
<body> | |
<div id="timeout"></div> | |
<script> | |
// 自执行函数 | |
(function timeout () { | |
const oneHour = 60 * 60 | |
const oneDay = oneHour * 24 | |
const oneYear = oneDay * 365 | |
const last = (new Date('2017-05-31T23:18:00')).getTime() | |
const now = (new Date()).getTime() | |
const second = (now - last) / 1000 | |
document.getElementById('timeout').innerText = [ | |
parseInt(second / oneYear) + '年', | |
parseInt(second % oneYear / oneDay) + '天', | |
parseInt(second % oneDay / oneHour) + '小时', | |
parseInt(second % oneHour / 60) + '分', | |
parseInt(second % 60) + '秒' | |
] | |
.join('') | |
.replace(/\b(\d)\b/g, '0$1') | |
.replace(/\b(\d+)\b/g, ' $1 ') | |
.replace(/(\s00\s([^\s]+))?/g, '') | |
setTimeout(() => timeout(), 1000) | |
})() | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment