You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							71 lines
						
					
					
						
							1.9 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							71 lines
						
					
					
						
							1.9 KiB
						
					
					
				
								/**
							 | 
						|
								 * @description 格式化任意时间
							 | 
						|
								 * @param {type} date 
							 | 
						|
								 * @return { fmt }
							 | 
						|
								 */
							 | 
						|
								export default function dateFtt(date){
							 | 
						|
									return parseInt(date / 60) + ":" + date % 60
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								/**
							 | 
						|
								 * 日期格式化
							 | 
						|
								 */
							 | 
						|
								export function dateFormat(date, format) {
							 | 
						|
								  format = format || 'yyyy-MM-dd hh:mm:ss';
							 | 
						|
								  if (date !== 'Invalid Date') {
							 | 
						|
								    let o = {
							 | 
						|
								      "M+": date.getMonth() + 1, //month
							 | 
						|
								      "d+": date.getDate(), //day
							 | 
						|
								      "h+": date.getHours(), //hour
							 | 
						|
								      "m+": date.getMinutes(), //minute
							 | 
						|
								      "s+": date.getSeconds(), //second
							 | 
						|
								      "q+": Math.floor((date.getMonth() + 3) / 3), //quarter
							 | 
						|
								      "S": date.getMilliseconds() //millisecond
							 | 
						|
								    }
							 | 
						|
								    if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
							 | 
						|
								      (date.getFullYear() + "").substr(4 - RegExp.$1.length));
							 | 
						|
								    for (let k in o)
							 | 
						|
								      if (new RegExp("(" + k + ")").test(format))
							 | 
						|
								        format = format.replace(RegExp.$1,
							 | 
						|
								          RegExp.$1.length === 1 ? o[k] :
							 | 
						|
								            ("00" + o[k]).substr(("" + o[k]).length));
							 | 
						|
								    return format;
							 | 
						|
								  }
							 | 
						|
								  return '';
							 | 
						|
								
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								/**
							 | 
						|
								 * 生成对应的时间字符串
							 | 
						|
								 */
							 | 
						|
								export function recordTime(options = {}){
							 | 
						|
									if(Object.prototype.toString.call(options.time) !== '[object Date]'){
							 | 
						|
										options.time = new Date();
							 | 
						|
									}
							 | 
						|
									if(typeof options.separator === 'undefined'){
							 | 
						|
										options.separator = "-";
							 | 
						|
									}
							 | 
						|
									if(typeof options.swf === 'undefined'){
							 | 
						|
										options.swf = "all";
							 | 
						|
									}
							 | 
						|
									let { time, separator,  swf } = options;
							 | 
						|
									
							 | 
						|
									function cover(par) {
							 | 
						|
										par = par.toString()[1] ? par : "0" + par;
							 | 
						|
										return par;
							 | 
						|
									}
							 | 
						|
									let year = time.getFullYear();
							 | 
						|
									let month = time.getMonth() + 1;
							 | 
						|
									let day = time.getDate();
							 | 
						|
									let hour = time.getHours();
							 | 
						|
									let min = time.getMinutes();
							 | 
						|
									let ppn = time.getSeconds();
							 | 
						|
									if(swf === "time"){
							 | 
						|
										return [hour, min, ppn].map(cover).join(":");
							 | 
						|
									}else if(swf === "date"){
							 | 
						|
										return [year, month, day].map(cover).join(String(separator));
							 | 
						|
									}else{
							 | 
						|
									return [year, month, day].map(cover).join(String(separator)) +" "+ [hour, min, ppn].map(cover).join(":");
							 | 
						|
									}
							 | 
						|
								}
							 |