const formatTime = date => {
  console.log(date);
  const day = parseInt(date / 1000 / 60 / 60 / 24);
  const hour = parseInt(date / 1000 / 60 / 60  % 24);
  const minute = parseInt(date / 1000 / 60 % 60);
  const arr = [hour, minute].map(formatNumber);
  arr.unshift(day);
  return arr
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}
//时间戳转时间
function formatDate(time, flag) {
	const t = new Date(time); 
	const tf = function(i){return (i < 10 ? '0' : '') + i};
	const year = t.getFullYear();
	const month = tf(t.getMonth() + 1);
	const day = tf(t.getDate());
	const hour = tf(t.getHours());
	const minute = tf(t.getMinutes());
	//console.log( month + '月' + day + '日' + hour + ':' + minute);
	if(flag == 1) {
		return  month + '月' + day + '日' + ' ' + hour + ':' + minute;
	}else if(flag == 2) {
		return year + '-' + month + '-' + day
	}else if(flag == 3){
		return month + '-' + day + ' ' + hour + ':' + minute;
	}
}
module.exports = {
  formatTime: formatTime,
  formatDate
}
