好!欢迎访问迷津渡口 现在时间是: 天气 °C ~ °C

迷津渡口

越感到迷惑 越接近真理

javascript统计网站运行时间动态输出每秒变化

大家都知道javascript产生时钟的方法,而这里小指要跟大家分享的网站运行时间动态输出就是从时钟产生演变而来。

话不多说,先把干货代码送上:

<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(2015, 10, 25, 0, 0, 0)).getTime() / 1000);
        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>
 < li > < i class = "iconfont" > & #xe633; < /i > 
 稳定运行: < span id = "htmer_time" class = "sm_padding" > < /span > < /li >

你可以把这段代码放置到需要输出运行时间的地方,例如本站是放到 footer.php的位置。

下面简单介绍一下这段代码

注意这个位置:

var create_time=Math.round(new Date(Date.UTC(2015,10,25,0,0,0)).getTime()/1000);

(2015,10,25,0,0,0)代表建站日期,这个时间代表2015年11月25日 00:00::00

你应该发现了月份的特殊性,从0-11代表1-12月,即比实际月份小1。

这一句:

document.getElementById("htmer_time").innerHTML=currentTimeHtml}setInterval(setTime,1000);

代表把id=htmer_time的内容变成运行时间并每秒变化,所以我们在下面需要有一个对应id的位置放置时间:

<span id="htmer_time" class="sm_padding"></span>

大概就是这样啦~



点赞2
   支持一下
挤眼 亲亲 咆哮 开心 想想 可怜 糗大了 委屈 哈哈 小声点 右哼哼 左哼哼 疑问 坏笑 赚钱啦 悲伤 耍酷 勾引 厉害 握手 耶 嘻嘻 害羞 鼓掌 馋嘴 抓狂 抱抱 围观 威武 给力
 点赞
 签到
 表情
 图片
 代码
提交评论

清空信息
关闭评论
javajoeshhi
 javajoeshhi 约 3 小时前回复
#115
<a href="http://www.facenextday.com/yeezy-boost-350-svart-new-butye">yeezy boost 350 svart new</a> <a href="http://www.mellowsblues.com/nike-free-5.0-2014-marron-rose-obuvd">nike free 5.0 2014 marron rose</a> <a href="http://www.stackdotnet.com/nike-flynit-air-max-mujeres-gris-oro-obuvg">nike flynit air max mujeres gris oro</a> <a href="http://www.donatelia.com/nike-kd-iv-for-vendita-a-buon-mercato-schuhef">nike kd iv for vendita a buon mercato</a> <a href="http://www.jafcosupply.com/nike-air-huarache-nm-s%C3%B8lv-sort-obuve">nike air huarache nm s酶lv sort</a> <a href="http://www.kanaldtvizle.com/nike-kyrie-1-dark-grigio-for-vendita-butye">nike kyrie 1 dark grigio for vendita</a>
javajoeshhi http://www.javajoeshhi.com/
johngerretsen
 johngerretsen 约 3 小时前回复
#114
<a href="http://www.katasuto.com/laquon-treadwell-youth-limited-purple-jersey-nike-nfl-minnesota-vikings-vapor-untouchable-home-11-nflr">laquon treadwell youth limited purple jersey nike nfl minnesota vikings vapor untouchable home 11</a> <a href="http://www.lapcomit.com/nike-hyperdunk-2014-low-hvit-bl%C3%A5-butyg">nike hyperdunk 2014 low hvit bl氓</a> <a href="http://www.nishuran.com/nike-kings-8-bogdan-bogdanovic-black-nba-swingman-statement-edition-jersey-nflz">nike kings 8 bogdan bogdanovic black nba swingman statement edition jersey</a> <a href="http://www.notilive.com/limited-nike-olive-youth-jamize-olawale-jersey-nfl-49-dallas-cowboys-2017-salute-to-service-nflw">limited nike olive youth jamize olawale jersey nfl 49 dallas cowboys 2017 salute to service</a> <a href="http://www.dibaricapital.com/adidas-ultra-boost-bleu-violet-chaussuresa">adidas ultra boost bleu violet</a> <a href="http://www.eaudurable.com/adidas-zx-700-lilla-gul-hypervenoms-butya">adidas zx 700 lilla gul hypervenoms</a>
johngerretsen http://www.johngerretsen.com/
djprofi
 djprofi 约 9 小时前回复
#113
<a href="http://www.getmohrfit.com/nike-air-presto-se-violet-rose-kurpesc">nike air presto se violet rose</a> <a href="http://www.lovehosaga.com/air-jordan-retro-5-low-bianca-scarpec">air jordan retro 5 low bianca</a> <a href="http://www.kidminpros.com/mennns-asics-gel-hyper-33-r%C3%B8d-rosa-schuhed">mennns asics gel hyper 33 r酶d rosa</a> <a href="http://www.typecomment.com/nike-air-max-95-bianca-grigio-blu-obuvf">nike air max 95 bianca grigio blu</a> <a href="http://www.minstrelhouse.com/le-coq-sportif-kvinners-sko-gull-butya">le coq sportif kvinners sko gull</a> <a href="http://www.barrettmark.com/air-jordan-12-gr%C3%BCn-butya">air jordan 12 gr眉n</a>
djprofi http://www.djprofi.com/
dkstekstil
 dkstekstil 2019-03-18 16:16回复
#112
<a href="http://www.theskifanatic.com/under-armour-curry-2-alle-gr%C3%B8n-skoj">under armour curry 2 alle gr酶n</a> <a href="http://www.bestoftumblr.com/air-jordan-retro-10-kvinners-rosa-oransje-obuvi">air jordan retro 10 kvinners rosa oransje</a> <a href="http://www.thehogrider.com/kvinners-air-yeezy-ii-2-sp-max-90-gr%C3%B8nn-bl%C3%A5-obuvk">kvinners air yeezy ii 2 sp max 90 gr酶nn bl氓</a> <a href="http://www.artpreneure.com/kvinners-air-jordan-retro-1-r%C3%B8d-gr%C3%A5-obuvi">kvinners air jordan retro 1 r酶d gr氓</a> <a href="http://www.thefarmergirl.com/nike-roshe-run-speckle-verde-zapatosk">nike roshe run speckle verde</a> <a href="http://www.shetablink.com/coach-legacy-swingpack-in-signature-medium-camel-crossbody-bags-coachh">coach legacy swingpack in signature medium camel crossbody bags</a>
[url=http://www.dkstekstil.com/]dkstekstil[/url]
balloonpunkt
 balloonpunkt 2019-03-18 14:07回复
#111
<a href="http://www.rawhouseibiza.com/giannis-antetokounmpo-jersey-t-shirt-nflz">giannis antetokounmpo jersey t shirt</a> <a href="http://www.startnimble.com/air-jordan-1-high-noir-rouge-obuvd">air jordan 1 high noir rouge</a> <a href="http://www.tlgwebsterny.com/hommes-supra-tk-society-violet-argent-scarpec">hommes supra tk society violet argent</a> <a href="http://www.vendsweeps.com/hombres-nike-air-max-thea-p%C3%BArpura-blanco-kurpesb">hombres nike air max thea p煤rpura blanco</a> <a href="http://www.zealouslyzika.com/nfl-nike-pittsburgh-steelers-25-artie-burns-ash-one-color-pullover-hoodie-nflr">nfl nike pittsburgh steelers 25 artie burns ash one color pullover hoodie</a> <a href="http://www.zlotyul.com/nike-free-tr-5.0-v4-pure-platinum-svart-butyg">nike free tr 5.0 v4 pure platinum svart</a>
balloonpunkt http://www.balloonpunkt.com/
clickstroy
 clickstroy 2019-03-17 21:47回复
#110
<a href="http://www.ortzproducts.com/hommes-nike-air-max-tailwind-8-blanc-vert-chaussuresl">hommes nike air max tailwind 8 blanc vert</a> <a href="http://www.cooterscamera.com/nike-kobe-icon-amarillo-verde-zapatosq">nike kobe icon amarillo verde</a> <a href="http://www.marjalfun.com/air-jordan-retro-13-kvinders-r%C3%B8d-lilla-skoj">air jordan retro 13 kvinders r酶d lilla</a> <a href="http://www.alecsblog.com/nike-zoom-structure-20-kvinners-hvit-svart-obuvi">nike zoom structure 20 kvinners hvit svart</a> <a href="http://www.troudumonde.com/mujeres-asics-gel-noosa-tri-7-plata-rosado-zapatosk">mujeres asics gel noosa tri 7 plata rosado</a> <a href="http://www.smilesdrdavid.com/jordan-gamma-bl%C3%A5-skoq">jordan gamma bl氓</a>
clickstroy http://www.clickstroy.com/
jobstodayng
 jobstodayng 2019-03-16 23:47回复
#109
<a href="http://www.diplomabroad.com/nero-and-bianca-converse-scarpe-scarpei">nero and bianca converse scarpe</a> <a href="http://www.trechadental.com/adidas-ultra-boost-mujer-azul-zapatosh">adidas ultra boost mujer azul</a> <a href="http://www.akhbarsanaye.com/air-max-light-essential-hvid-sort-mystic-gr%C3%B8n-skok">air max light essential hvid sort mystic gr酶n</a> <a href="http://www.timxes.com/menn-nike-air-max-90-gr%C3%B8nn-svart-hvit-obuvi">menn nike air max 90 gr酶nn svart hvit</a> <a href="http://www.leadercheetah.com/adidas-ace-16.3-blanco-and-oro-zapatosl">adidas ace 16.3 blanco and oro</a> <a href="http://www.arealleader.com/ray-ban-wayfarer-uk-sunglassesh">ray ban wayfarer uk</a>
jobstodayng http://www.jobstodayng.com/
marinersdiary
 marinersdiary 2019-03-14 17:04回复
#108
<a href="http://www.laketreepress.com/nike-air-max-90-carved-rosado-blanco-zapatosk">nike air max 90 carved rosado blanco</a> <a href="http://www.prohaarklinik.com/kvinders-air-jordan-retro-3-lilla-appelsin-skoi">kvinders air jordan retro 3 lilla appelsin</a> <a href="http://www.bonfanticare.com/adidas-gazelle-boost-bl%C3%A5-oransje-obuvl">adidas gazelle boost bl氓 oransje</a> <a href="http://www.antoniopagni.com/womens-nike-free-tr-fit-purple-red-shoesh">womens nike free tr fit purple red</a> <a href="http://www.wcshosting.com/adidas-forum-mid-grigio-cielo-blu-scarpei">adidas forum mid grigio cielo blu</a> <a href="http://www.biddingstream.com/adidas-neo-leisure-schwarz-orangen-schuhej">adidas neo leisure schwarz orangen</a>
marinersdiary http://www.marinersdiary.com/
trumpchokes
 trumpchokes 2019-03-14 14:15回复
#107
<a href="http://www.scottdepot.com/mujeres-air-jordan-retro-12-todas-naranja-schuheg">mujeres air jordan retro 12 todas naranja</a> <a href="http://www.troyafolklor.com/ralph-lauren-hommes-canvas-dark-olive-polo-baskets-polou">ralph lauren hommes canvas dark olive polo baskets</a> <a href="http://www.ampflightads.com/lebron-14-low-bianca-nero-chaussuresa">lebron 14 low bianca nero</a> <a href="http://www.edotokyolabo.com/nike-huarache-lyser%C3%B8d-and-sort-schuhed">nike huarache lyser酶d and sort</a> <a href="http://www.euniscpa.com/nike-blazer-mid-suede-junior-bleu-scarpea">nike blazer mid suede junior bleu</a> <a href="http://www.governisation.com/kvinners-new-balance-360-beige-kurpese">kvinners new balance 360 beige</a>
trumpchokes http://www.trumpchokes.com/
fishmackerel
 fishmackerel 2019-03-14 12:47回复
#106
<a href="http://www.hinogi.com/kvinners-nike-shox-turbo-21-bl%C3%A5-hvit-obuvl">kvinners nike shox turbo 21 bl氓 hvit</a> <a href="http://www.prontosignsus.com/adidas-neo-leather-sky-blue-orange-shoesh">adidas neo leather sky blue orange</a> <a href="http://www.ticahome.com/nike-lebron-13-gituttio-rosa-scarpei">nike lebron 13 gituttio rosa</a> <a href="http://www.prformusic.com/air-jordan-retro-7-gamma-blau-gold-schuhej">air jordan retro 7 gamma blau gold</a> <a href="http://www.tatilblogu.com/texas-am-aggies-top-of-the-world-ncaa-hustle-hard-flex-cap-hath">texas am aggies top of the world ncaa hustle hard flex cap</a> <a href="http://www.danieladirosa.com/nike-dunk-gris-argent-chaussuresh">nike dunk gris argent</a>
fishmackerel http://www.fishmackerel.com/
顶部留言底部
 00:00/00:00
我想和你虚度时光 - 花房姑娘(9)
  1. 我想和你虚度时光
  2. 花房姑娘
  3. 恋恋风尘
  4. 我喜爱一切不彻底的事物
  5. 我的心里是满的
  6. Long Way
  7. 给少年的歌
  8. 晴日共剪窗
  9. 天上的月你的脸