var dateDiff = function( hisTime,nowTime ) {
hisTime = new Date( hisTime.replace("-","/") ).getTime()
var now =nowTime?nowTime:new Date().getTime(),
diffValue = now - hisTime,
result='',
minute = 1000 * 60,
hour = minute * 60,
day = hour * 24,
halfamonth = day * 15,
month = day * 30,
year = month * 12,
_year = diffValue/year,
_month =diffValue/month,
_week =diffValue/(7*day),
_day =diffValue/day,
_hour =diffValue/hour,
_min =diffValue/minute;
if(_year>=1) result=parseInt(_year) + "年前";
else if(_month>=1) result=parseInt(_month) + "个月前";
else if(_week>=1) result=parseInt(_week) + "周前";
else if(_day>=1) result=parseInt(_day) +"天前";
else if(_hour>=1) result=parseInt(_hour) +"个小时前";
else if(_min>=1) result=parseInt(_min) +"分钟前";
else result="刚刚";
return result;
}
时间转换
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- (function() { 'use strict'; /** * myApp Module * * Descri...
- 看到一篇好的文章特此分享 NSDateFormatter*formatter = [[NSDateFormatte...
- 项目用到了从服务器返回距离1970年多少秒的发布的数据,然后计算多少当前时间距离消息发布的时间,1分钟以内显示几秒...
- MySQL datediff(date1,date2):两个日期相减 date1 - date2,返回天数。sel...