扣丁书屋

JS 获取当前年份,月份

1年以前  |  阅读数:36 次  |    

function doHandleDate() {
    var myDate = new Date();
    var tYear = myDate.getFullYear();
    var tMonth = myDate.getMonth();

    var m = tMonth + 1;
    if (m.toString().length == 1) {
        m = "0" + m;
    }
    return tYear +'-'+ m;
}
function doHandleYear(tYear) {
    var myDate = new Date();
    var tYear = myDate.getFullYear();

    return tYear;
}
function doHandleMonth() {
    var myDate = new Date();
    var tMonth = myDate.getMonth();

    var m = tMonth + 1;
    if (m.toString().length == 1) {
        m = "0" + m;
    }
    return m;
}

相关文章: