03azfa
Last Updated: February 25, 2016
·
331
· richardgong1987
Psb  1

Deal with Date Type

1, how to return our custom days of the week
You knew getDay() method just return a number from 0-6; 0 representative Sunday, 1 representative Monday, 2 representative Tuesday ,3 representative Wednesday, 4 representative Thursday , 5 representative Friday, 6 representative Saturday;

So,
function myweek (argument) {
var day = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
var dd = new Date();
return day[dd.getDay()];
}
console.log(myweek());

2,get different Month
function diffMonth (aDate, bDate) {
var ad = new Date(aDate);
var bd = new Date(bDate);

    var adYear = ad.getFullYear();
    var bdYear = bd.getFullYear();

    var adM = ad.getMonth();
    var bdM = bd.getMonth();

    return (adYear - bdYear) * 12 + (adM - bdM);

}
console.log(diffMonth( '2014/3/20', '2013/1/2'));//14

idea: To calculate different month, we need to covert Date type to Month, and then to calcite;

Say Thanks
Respond