時間中間鍵的整理
一下內容是對數據接口返回的時間節點處理方法很管用的哦
import { Pipe, PipeTransform } from '@angular/core';@Pipe({ name: 'interval'})export class IntervalPipe implements PipeTransform { transform(value: any): any { let date = new Date(value) if (!date) { return '' } let now = new Date() let year = now.getFullYear() - date.getFullYear() if (year) { return year + '年前' } let month = now.getMonth() - date.getMonth() if (month) { return month + '月前' } let day = now.getDate() - date.getDate() if (day) { return day + '天前' } let hour = now.getHours() - date.getHours() if (hour) { return hour + '小時前' } let min = now.getMinutes() - date.getMinutes() if (min) { return min + '分鐘前' } return '剛剛'; }}
如有疑問請留言或者到本站社區交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
新聞熱點
疑難解答
圖片精選