1. 程式人生 > 其它 >判斷時間多少分鐘前,小時前

判斷時間多少分鐘前,小時前

/1000拿到秒數,/60拿到分鐘

	 res.list.map((item, index) => {
                        item.time = dayjs(item.createAt).valueOf()
                        let now = Date.now();
                        Vue.set(item, "second", Math.ceil((now - item.time) / 1000));
                        Vue.set(item, "mins"
, Math.ceil((now - item.time) / 1000 / 60)); Vue.set( item, "hour", Math.ceil((now - item.time) / 1000 / 60 / 60) ); Vue.set( item,
"day", Math.ceil((now - item.time) / 1000 / 60 / 60 / 24) ); });
  <small v-if="item.day && item.day < 30 && item.day >= 1">
                  {{ Math.ceil(item.
day) }}天前 </small> <small v-if="item.day && item.day >= 30"> {{ parseInt(item.day / 30) }}月前 </small> <small v-if="item.day && item.day / 24 > 0 && item.day < 1"> {{ Math.ceil(item.day / 24) }}小時前 </small>