欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

javascript學(xué)習(xí)筆記(六) Date 日期類型

 更新時(shí)間:2012年06月19日 23:04:15   作者:  
javascript學(xué)習(xí)筆記之Date 日期類型介紹,需要的朋友可以參考下
1.創(chuàng)建日期對(duì)象
復(fù)制代碼 代碼如下:

var now = new Date(); //獲得當(dāng)前系統(tǒng)日期和時(shí)間
var someDate = new Date(Date.parse("May 25,2012"));
var someDate = new Date("May 25,2012"); //與上相同
var someDate = new Date(Date.UTC(2010,0)); //GMT時(shí)間2010年1月1日凌晨0時(shí)
var someDate = new Date(2010,0); //與上相同
var someDate = new Date(Date.UTC(2010,4,5,17,55,55)); //GMT時(shí)間2010年5月日下午5:55:55,月和時(shí)以0為基數(shù),0表示一月
var someDate = new Date(2010,4,5,17,55,55); //與上相同

Date.parse()和Date.UTC()返回相應(yīng)日期的毫秒數(shù),Date.UTC()參數(shù)分別是:年、月、日、時(shí)、分、秒、毫秒.至少有年和月2個(gè)參數(shù).其中月和時(shí)以0為基數(shù)
2.日期的比較
復(fù)制代碼 代碼如下:

var date1 = new Date(2007,0,1);
var date2 = new Date(2007,1,1);
alert(date1>date2); //false
alert(date1<date2); //true

3.日期格式化方法及獲得設(shè)置日期方法
復(fù)制代碼 代碼如下:

View Code
toDateString()
toTimeString()
toLocaleDateString() //如2007年1月1日
toLocaleTimeString() //如13:55:55
toUTCString()
getTime() //返回日期的毫秒數(shù)
setTime()
getFullYear() //獲得年份,如2007
setFullYear()
getMonth() //獲得月份,0表示一月
setMonth() //設(shè)置月份,0表示一月,超過11增加年份
getDate() //獲得日期中的天數(shù)
setDate() //設(shè)置天數(shù),超過31增加月份
getDay() //獲得星期,0表示星期日,6表示星期六
getHours() //獲得小時(shí),0~23
setHours() //設(shè)置小時(shí),0~23
getMinutes() //獲得分鐘,0~59
setMinutes() //設(shè)置分鐘,0~59
getSeconds() //獲得秒數(shù),0~59
setSeconds() //設(shè)置秒數(shù),0~59
getMilliseconds() //獲得毫秒
setMilliseconds() //設(shè)置毫秒

相關(guān)文章

最新評(píng)論