前言
通用JS代码,emlog,wordpress,zblog,typecho通用,久伴以前是不想搞这个运行时间的,但是怕时间冲淡了博客坚持下去的欲望,还是整一个吧
截图
代码
- <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() {
- // 博客创建时间秒数,时间格式中,月比较特殊,是从0开始的,所以想要显示5月,得写4才行,如下
- var create_time = Math.round(new Date(Date.UTC(2013, 4, 22, 0, 0, 0))
- .getTime() / 1000);
- // 当前时间秒数,增加时区的差异
- var timestamp = Math.round((new Date().getTime() + 8 * 60 * 60 * 1000) / 1000);
- currentTime = secondToDate((timestamp – create_time));
- currentTimeHtml = currentTime[0] + ‘年’ + currentTime[1] + ‘天’
- + currentTime[2] + ‘时’ + currentTime[3] + ‘分’ + currentTime[4]
- + ‘秒’;
- document.getElementById(“htmer_time”).innerHTML = currentTimeHtml;
- }
- setInterval(setTime, 1000);
- </script>
- 网站运行:<span id=“htmer_time” style=“color: red;”></span>
- <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() {
- // 博客创建时间秒数,时间格式中,月比较特殊,是从0开始的,所以想要显示5月,得写4才行,如下
- var create_time = Math.round(new Date(Date.UTC(2018, 1, 22, 0, 0, 0))
- .getTime() / 1000);
- // 当前时间秒数,增加时区的差异
- var timestamp = Math.round((new Date().getTime() + 8 * 60 * 60 * 1000) / 1000);
- currentTime = secondToDate((timestamp – create_time));
- currentTimeHtml = currentTime[0] + ‘年’ + currentTime[1] + ‘天’
- + currentTime[2] + ‘时’ + currentTime[3] + ‘分’ + currentTime[4]
- + ‘秒’;
- document.getElementById(“htmer_time”).innerHTML = currentTimeHtml;
- }
- setInterval(setTime, 1000);
- </script>
加群入久伴博客官方微信群
加入久伴官方微信群有啥优势?
1.文章内部资源由于时间久远可能失效,加群,群内可以第一时间反馈
2.网站中教程不一定适用任何人,加群可以第一时间咨询并解决您得疑惑
3.你游荡于互联网,也需要群体,加群一起互动交流,畅所欲言
扫描下方二维码即可加入交流讨论
