85 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
			
		
		
	
	
			85 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
| 
 | |
| //该方法用于给日期、时间补零
 | |
| function addZero(num) {
 | |
|   if (parseInt(num) < 10) {
 | |
|     num = "0" + num
 | |
|   }
 | |
|   return num
 | |
| }
 | |
| //把毫秒数转化成具体日期   2021-06-04
 | |
| //参数 毫秒数  
 | |
| function formatMsToDate(ms) {
 | |
|   if (ms) {
 | |
|     var oDate = new Date(ms),
 | |
|       oYear = oDate.getFullYear(),
 | |
|       oMonth = oDate.getMonth() + 1,
 | |
|       oDay = oDate.getDate(),
 | |
|       // oHour = oDate.getHours(),
 | |
|       // oMin = oDate.getMinutes(),
 | |
|       // oSen = oDate.getSeconds(),
 | |
|       oTime = oYear + '-' + addZero(oMonth) + '-' + addZero(oDay);
 | |
|     return oTime;
 | |
|   } else {
 | |
|     return ""
 | |
|   }
 | |
| }
 | |
| //判断值是否为空
 | |
| function isEmpty(v) {
 | |
|   switch (typeof v) {
 | |
|     case 'undefined':
 | |
|       return true;
 | |
|     case 'string':
 | |
|       if (v.replace(/(^[ \t\n\r]*)|([ \t\n\r]*$)/g, '').length == 0) return true;
 | |
|       break;
 | |
|     case 'boolean':
 | |
|       if (!v) return true;
 | |
|       break;
 | |
|     case 'number':
 | |
|       if (0 === v || isNaN(v)) return true;
 | |
|       break;
 | |
|     case 'object':
 | |
|       if (null === v || v.length === 0) return true;
 | |
|       for (var i in v) {
 | |
|         return false;
 | |
|       }
 | |
|       return true;
 | |
|   }
 | |
|   return false;
 | |
| }
 | |
| function formatSeconds(second_time) {
 | |
|   var time = parseInt(second_time) + "天";
 | |
|   if (parseInt(second_time) >= 60) {
 | |
|     var second = parseInt(second_time) % 60;
 | |
|     var min = parseInt(second_time / 60);
 | |
|     if (second == 0) {
 | |
|       // time = min + "分";
 | |
|     } else {
 | |
|       // time = min + "分" + second + "秒";
 | |
|     }
 | |
|     if (min > 60) {
 | |
|       min = parseInt(second_time / 60) % 60;
 | |
|       var hour = parseInt(parseInt(second_time / 60) / 60);
 | |
|       if (second == 0) {
 | |
|         // time = hour + "小时";
 | |
|       } else {
 | |
|         // time = hour + "小时";
 | |
|       }
 | |
|       if (hour > 24) {
 | |
|         hour = parseInt(parseInt(second_time / 60) / 60) % 24;
 | |
|         var day = parseInt(parseInt(parseInt(second_time / 60) / 60) / 24);
 | |
|         if (second == 0) {
 | |
|           time = day + "天";
 | |
|         } else {
 | |
|           time = day + "天";
 | |
|         }
 | |
|       }
 | |
|     }
 | |
| 
 | |
|   } else {
 | |
|     time = time;
 | |
|   }
 | |
|   return time;
 | |
| }
 | |
| export {
 | |
|   formatMsToDate,isEmpty,formatSeconds
 | |
| } |