demo-day-one
v3.3.0
Published
```JavaScript class Moment{ constructor(time){ this.time=time; this.change() } change(){ let nowtime = new Date(); let newtime = new Date(this.time);
Downloads
6
Readme
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