[javaScript]今天业务上用到一个毫秒转年月日时分秒的功能,网上找了下,没有,自己随便写了个。记录

直接贴代码。

function mathTime(ms){
	var sec = ms/1000;
	var min = sec/60;
	if(min>=1){
		var h = min/60;
		if(h>=1){
			var d = h/24;
			if(d>=1){
				var m = d/30.5;
				if(m>=1){
					var y = m/12;
					if(y>=1){
						return Math.floor(y)+"年"+Math.floor(sec%31622400/2635200)+"月"+Math.floor(sec%2635200/86400)+"天"+Math.floor(sec%86400/3600)+"小时"+Math.floor(sec%3600/60)+"分"+Math.floor(sec%60)+"秒";
					}else{
						return Math.floor(m)+"月"+Math.floor(sec%2635200/86400)+"天"+Math.floor(sec%86400/3600)+"小时"+Math.floor(sec%3600/60)+"分"+Math.floor(sec%60)+"秒";
					}
				}else{
					return Math.floor(d)+"天"+Math.floor(sec%86400/3600)+"小时"+Math.floor(sec%3600/60)+"分"+Math.floor(sec%60)+"秒";
				}
			}else{
				return Math.floor(h)+"小时"+Math.floor(sec%3600/60)+"分"+Math.floor(sec%60)+"秒";
			}
		}else{
			return tim = Math.floor(min)+"分"+Math.floor(sec%60)+"秒";
		}
	}else{
		return sec+"秒";
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值