欢迎来到代码驿站!

JAVA代码

当前位置:首页 > 软件编程 > JAVA代码

时间中间键的整理

时间:2021-03-17 09:39:36|栏目:JAVA代码|点击:

时间中间键的整理

一下内容是对数据接口返回的时间节点处理方法很管用的哦


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 '刚刚';
 }

}

如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

上一篇:JAVA--HashMap热门面试题

栏    目:JAVA代码

下一篇:java将图片至暗的实现方法

本文标题:时间中间键的整理

本文地址:http://www.codeinn.net/misctech/82254.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有