demo-day-one

3.3.0 • Public • Published

momennt

class Moment{
    constructor(time){
        this.time=time;
        this.change()
    }
    change(){
        let nowtime = new Date();
        let newtime = new Date(this.time);

        if(nowtime*1 > newtime*1){
            let year = Math.floor((nowtime*1-newtime*1)/1000/60/60/24/30/12%365);
            let month = Math.floor((nowtime*1-newtime*1)/1000/60/60/24/30%12);
            let day = Math.floor((nowtime*1-newtime*1)/1000/60/60%24);
            let hour = Math.floor((nowtime*1-newtime*1)/1000/60%60);
            console.log(`${year}${month}${day}${hour}前`);
        }else{
            let year = Math.floor((newtime*1-nowtime*1)/1000/60/60/24/30/12%365);
            let month = Math.floor((newtime*1-nowtime*1)/1000/60/60/24/30%12);
            let day = Math.floor((newtime*1-nowtime*1)/1000/60/60%24);
            let hour = Math.floor((newtime*1-newtime*1)/1000/60%60);
            console.log(`${year}${month}${day}${hour}后`);
        }
    }
}

module.exports = Moment

Readme

Keywords

none

Package Sidebar

Install

npm i demo-day-one

Weekly Downloads

2

Version

3.3.0

License

ISC

Unpacked Size

2.34 kB

Total Files

3

Last publish

Collaborators

  • wangshuaitao