js中格式化毫秒值问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/caox_90/article/details/53283460

js格式化毫秒值字符串报无效日期

js中格式化毫秒值需要将毫秒值转变成数字类型在进行转化

var date = parseInt($(this).html());
		if(date != null){
			var time = new Date(date);
			var year = time.getFullYear();
			var month = time.getMonth()+1;
			if(month < 10){
				month="0"+month;
			}
			var date = time.getDate();
			if(date < 10){
				date="0"+date;
			}
			var hours = time.getHours();
			if(hours < 10){
				hours="0"+hours;
			}
			var min = time.getMinutes();
			if(min < 10){
				min="0"+min;
			}
			var sec = time.getSeconds();
			if(sec < 10){
				sec="0"+sec;
			}
			var d = year+"-"+month+"-"+date+" "+hours+":"+min+":"+sec;
			$(this).html(d);
		}else{
			$(this).html("--:--");
		}


猜你喜欢

转载自blog.csdn.net/caox_90/article/details/53283460