關於datepicker如何擷取月中日長

來源:互聯網
上載者:User

我百思不得姐啊。苦逼的diao絲 ,下面是兩個實現,不知道還有沒有更好方法 。期盼大牛不吝賜教。
datePicker.date = function(date, type) {
type = this.display[(type || "realtime")] || type;
try {
type = type.replace("YY", date.getFullYear())
.replace("MM", (date.getMonth()+1))
.replace("DD", date.getDate())
.replace("hh", date.getHours())
.replace("mm", date.getMinutes())
.replace("ss", date.getSeconds());
}
catch(e){
type = new Date;    
}
finally{
return type;
}
};
datePicker.monthInfo = function(year, month) {
var d1 = datePicker.date(),
d2 = datePicker.date();
d1.setFullYear(year);
d1.setMonth(month - 1);
d1.setDate(1);
 
d2.setFullYear(year);
d2.setMonth(month);
d2.setDate(1);
try {
return {
day: ((d2.getTime() - d1.getTime()) / 86400000),
week: d1.getDay()
}
}
finally {
d1 = d2 = null;
}
 
};
datePicker.monthInfo2 = function(year, month) {
var days = [31,30,29,28],
date = datePicker.date(),
i = [1,3,5,7,8,10,12,4,6,9,11,2].indexOf(month-0);
i = (i <= 6) ? 0 : (i <= 10) ? 1 : this.checkYear(year) ? 2 : 3;
 
date.setFullYear(year);
date.setMonth(month - 1);
date.setDate(1);
try {
return {
day : days[i],
week: date.getDay()
};
}
finally {
days = date = i = null;
}
 
};
datePicker.checkYear = function (year) {
return ((!year%4 && !year%100) || !year%400) && (year !==3200);
};
  
 
開始 到結束 只是那麼個過程。結束了 就忘記吧。

 


摘自 AlfredLee

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.