46 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
			
		
		
	
	
			46 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
const formatTime = date => {
 | 
						|
  const year = date.getFullYear()
 | 
						|
  const month = date.getMonth() + 1
 | 
						|
  const day = date.getDate()
 | 
						|
  const hour = date.getHours()
 | 
						|
  const minute = date.getMinutes()
 | 
						|
  const second = date.getSeconds()
 | 
						|
 | 
						|
  return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
 | 
						|
}
 | 
						|
 | 
						|
const formatNumber = n => {
 | 
						|
  n = n.toString()
 | 
						|
  return n[1] ? n : '0' + n
 | 
						|
}
 | 
						|
 | 
						|
function formatmil(mil) {
 | 
						|
  var allSecond = Math.floor(mil / 1000);
 | 
						|
  var h = Math.floor(allSecond / 3600);
 | 
						|
  var m = Math.floor((allSecond - h * 3600) / 60);
 | 
						|
  var s = Math.floor(allSecond - h * 3600 - m * 60);
 | 
						|
  h = toTow(h);
 | 
						|
  m = toTow(m);
 | 
						|
  s = toTow(s);
 | 
						|
  return h + ":" + m + ":" + s;
 | 
						|
}
 | 
						|
function formatSecond(val) {
 | 
						|
  var m = Math.floor(val/ 60)
 | 
						|
  var s = Math.floor(val - m * 60)
 | 
						|
  return m + '分' + s + '秒'
 | 
						|
}
 | 
						|
 | 
						|
function toTow(num) {
 | 
						|
  if (num < 10) {
 | 
						|
    return "0" + num;
 | 
						|
  } else {
 | 
						|
    return num;
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
module.exports = {
 | 
						|
  formatTime: formatTime,
 | 
						|
  formatmil: formatmil,
 | 
						|
  formatSecond: formatSecond
 | 
						|
}
 |