国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JavaScript > 正文

JavaScript中日期函數(shù)的相關(guān)操作知識(shí)

2019-11-20 09:18:58
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

時(shí)間對(duì)象是一個(gè)我們經(jīng)常要用到的對(duì)象,無(wú)論是做時(shí)間輸出、時(shí)間判斷等操作時(shí)都與這個(gè)對(duì)象離不開。除開JavaScript中的時(shí)間對(duì)象外,在VbScript中也有許多的時(shí)間對(duì)象,而且非常好用。下面還是按照我們的流程來(lái)進(jìn)行講解JavaScript中日期函數(shù)。

new Date()

new Date(milliseconds)

new Date(datestring)

new Date(year, month)

new Date(year, month, day)

new Date(year, month, day, hours)

new Date(year, month, day, hours, minutes)

new Date(year, month, day, hours, minutes, seconds)

new Date(year, month, day, hours, minutes, seconds, microseconds)

下面對(duì)

1.new Date(),沒有參數(shù)的時(shí)候,創(chuàng)建的是當(dāng)前時(shí)間日期對(duì)象。

2.new Date(milliseconds),當(dāng)參數(shù)為數(shù)字的時(shí)候,那么這個(gè)參數(shù)就是時(shí)間戳,被視為毫秒,創(chuàng)建一個(gè)距離1970年1月一日指定毫秒的時(shí)間日期對(duì)象。

3.new Date(datestring),此參數(shù)是一個(gè)字符串,并且此字符串一定能夠使用Date.parse()轉(zhuǎn)換。

4.以下六個(gè)構(gòu)造函數(shù)是精確定義:

  1).year,是一個(gè)整數(shù),如果是0-99,那么在此基礎(chǔ)上加1900,其他的都原樣返回。

  2).month,是一個(gè)整數(shù),范圍是0-11。

  3).day,是一個(gè)整數(shù),范圍是1-31。

  4).hours,是一個(gè)整數(shù),范圍是0-23。

  5).minutes,是一個(gè)整數(shù),范圍是0-59。

  6).seconds,是一個(gè)整數(shù),范圍是0-59。

  7).microseconds 是一個(gè)整數(shù),范圍是0-9999。

<html><head><title>時(shí)間戳轉(zhuǎn)化為年月日時(shí)分秒</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head><body></body></html><script>window.onload=function(){var now=new Date();//當(dāng)前系統(tǒng)時(shí)間 var shijianchuo = now.getTime();//獲取當(dāng)前時(shí)間戳alert("時(shí)間戳:"+shijianchuo);var nowdate = new Date(shijianchuo);//將時(shí)間戳轉(zhuǎn)化為日期對(duì)象var nowtime=nowdate.Format("yyyy-MM-dd hh:mm:ss");//格式化當(dāng)前系統(tǒng)時(shí)間,相當(dāng)于將時(shí)間戳轉(zhuǎn)化為年月日時(shí)分秒了alert("當(dāng)前時(shí)間:"+nowtime);}/*日期格式化:對(duì)Date的擴(kuò)展,將 Date 轉(zhuǎn)化為指定格式的String年(y)可以用1-4個(gè)占位符,季度(q)可以用1-2個(gè)占位符.月(M)、日(d)、小時(shí)(h)、分(m)、秒(s)可以用1-2個(gè)占位符.毫秒(S)只能用1個(gè)占位符(是1-3位的數(shù)字) 例子: (new Date()).Format("yyyy-MM-dd hh:mm:ss.S")(new Date()).Format("yyyy-MM-dd hh:mm:ss.S毫秒 第qq季度")*/Date.prototype.Format = function (fmt) { var o = {"M+": this.getMonth() + 1, //月 "d+": this.getDate(), //日 "h+": this.getHours(), //時(shí) "m+": this.getMinutes(), //分 "s+": this.getSeconds(), //秒 "q+": Math.floor((this.getMonth() + 3) / 3), //季度 "S": this.getMilliseconds() //毫秒 };if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));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;}</script>

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 儋州市| 都昌县| 莱州市| 郧西县| 亚东县| 阜新| 喀什市| 沧源| 额敏县| 靖西县| 习水县| 福泉市| 上林县| 南川市| 大竹县| 泽库县| 陆丰市| 吴旗县| 新邵县| 大田县| 共和县| 贵德县| 威海市| 浦东新区| 奇台县| 德化县| 阳东县| 巴中市| 鄢陵县| 桐乡市| 南京市| 报价| 股票| 千阳县| 内乡县| 碌曲县| 乐亭县| 长治县| 丹寨县| 巴塘县| 西平县|