function formatDateTime(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()
  
  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()
  
  return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

function formatTimeHHMM(date) {
	var hour = date.getHours()
	var minute = date.getMinutes()
	return [hour, minute].map(formatNumber).join(':');
}

function formatMMDDChinese(date) {
	var mm = date.getMonth() + 1
	var dd = date.getDate()
	return mm+"月"+dd+"日"
}

function formatDataMDW(date) {
	var weeks = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"]
	var mm = date.getMonth() + 1
	var dd = date.getDate()
	return mm + "月" + dd + "日(" + weeks[date.getDay()] + ")"
}

function formatYYYYMMDD(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()
  return [year, month, day].map(formatNumber).join('/')
}

function formatYYYYMMDD2(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()

  //var hour = date.getHours()
  //var minute = date.getMinutes()
  //var second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('-')
}

function formatDDMMYYYY(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()
  
  return [day, month, year].map(formatNumber).join('/')
}

function formatYearMonth(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  return [year, month].map(formatNumber).join('-')
}

function formatNumber(n) {
  n = n.toString()
  return n[1] ? n : '0' + n
}

module.exports = {
  formatDateTime: formatDateTime,
  formatTimeHHMM: formatTimeHHMM,
  formatMMDDChinese: formatMMDDChinese,
  formatDataMDW: formatDataMDW,
  formatYYYYMMDD: formatYYYYMMDD,
  formatYYYYMMDD2: formatYYYYMMDD2,
  formatDDMMYYYY: formatDDMMYYYY,
  formatYearMonth: formatYearMonth
}