const listtime = (val) => {
let result;
let timePublish = new Date(val); //传入时的时间
let timemeNow = new Date(); //现在的时间
let miunter = 1000 * 60; //分
let hour = miunter * 60; //时
let day = hour * 24; //天
let month = day * 30; //月
let year = month * 12; //年
let diffvalue = timemeNow - timePublish; //时间差是毫秒
let diffMonth = diffvalue / month;
let diffweek = diffvalue / (7 * day);
let diffday = diffvalue / day;
let diffhour = diffvalue / hour;
let diffminute = diffvalue / miunter;
let diffyear = diffvalue / year;
if (diffvalue < miunter) {
result = "刚刚";
} else if (diffyear > 1) {
result = parseInt(diffyear) + "年前";
} else if (diffMonth > 1) {
result = parseInt(diffMonth) + "月前";
} else if (diffweek > 1) {
result = parseInt(diffweek) + "周前";
} else if (diffday > 1) {
result = parseInt(diffday) + "天前";
} else if (diffhour > 1) {
result = parseInt(diffhour) + "小时前";
} else if (diffminute > 1) {
result = parseInt(diffminute) + "分钟前";
}
return result;
};
时间转换
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- /** *Util工具类 */ constUtil={}; /** *控制台日志打印 */ Util.debug=...
- (function() { 'use strict'; /** * myApp Module * * Descri...
- 看到一篇好的文章特此分享 NSDateFormatter*formatter = [[NSDateFormatte...
- 首先先说下12小时制的时间.12小时制的 12:50PM 对应 24小时制的12:5012小时制的 12:...