1.1.1-S • Published 3 years ago

day1-works v1.1.1-S

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

高级node的复习

//封装函数时间转换,
class Moment {

    //构造器
    constructor(time) {
        //赋值
        this.time = time;
    }

    //执行函数
    change() {
        let data = new Date(this.time);//转换保存过去输入的时间
        
        //现在的 新时间
        let nowtime = new Date();

        // 现在减去过去就等于的天数
        let newtim = nowtime - data;//减去过去的时间

        //年月份的转换
        let year = Math.floor(newtim / 1000 / 60 / 60 / 24 / 365),//年
            mother = Math.floor(newtim / 1000 / 60 / 60 / 24 / 30 % 12),//月
            day = Math.floor(newtim / 1000 / 60 / 60 / 24);//日

        //返回时间拼接
        return year + "年"+mother+"月"+day+"日";
    }

}
//打印
console.log(new Moment("2021-03-18").change());