亚洲最大看欧美片,亚洲图揄拍自拍另类图片,欧美精品v国产精品v呦,日本在线精品视频免费

  • 站長資訊網(wǎng)
    最全最豐富的資訊網(wǎng)站

    javascript如何轉(zhuǎn)換時間

    javascript轉(zhuǎn)換時間的方法:創(chuàng)建一個【util.js】文件,在里面重新封裝一下Date的format方法,代碼為【let date = new Date().Format("yyyy年M月dd日tEEEtHH:mm:ss")】。

    javascript如何轉(zhuǎn)換時間

    本教程操作環(huán)境:windows7系統(tǒng)、javascript1.8.5版,DELL G3電腦。

    javascript轉(zhuǎn)換時間的方法:

    創(chuàng)建一個util.js文件,在里面重新封裝一下Date的format方法:

    //Date的prototype 屬性可以向?qū)ο筇砑訉傩院头椒ā?   Date.prototype.Format = function(fmt) { var o = {     "M+": this.getMonth() + 1, //月份              "d+": this.getDate(), //日              "h+": this.getHours() % 12 === 0 ? 12 : this.getHours() % 12, //小時              "H+": this.getHours(), //小時              "m+": this.getMinutes(), //分              "s+": this.getSeconds(), //秒              "q+": Math.floor((this.getMonth() + 3) / 3), //季度              "S": this.getMilliseconds() //毫秒          }; var week = {     "0": "u65e5",     "1": "u4e00",     "2": "u4e8c",     "3": "u4e09",     "4": "u56db",     "5": "u4e94",     "6": "u516d" }; if (/(y+)/.test(fmt)) {     fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); } if (/(E+)/.test(fmt)) {     fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "u661fu671f" : "u5468") : "") + week[this.getDay() + ""]); } for (var k in o) {     if (new RegExp("(" + k + ")").test(fmt)) {         fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));     } } return fmt; };

    具體調(diào)用的時候就可以變得很方便,想要什么格式就可以形成什么格式,例如 年月日 星期幾 時分秒,做個簡單的例子,如果有哪里看不明白可以評論,我看見會給你解釋的。

    let date = new Date().Format("yyyy年MM月dd日tEEEtHH:mm:ss");         $("#date-now").html(date);

    相關(guān)免費(fèi)學(xué)習(xí)推薦:javascript學(xué)習(xí)教程

    贊(0)
    分享到: 更多 (0)
    網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號