class TimeUtil {

  getCurrentDate(): string {
    let dateTime = new Date()
    let month: string = JSON.stringify(dateTime.getMonth() + 1)
    let time = dateTime.getFullYear() + '-' + (dateTime.getMonth() + 1).toString().padStart(2, '0')
      + '-' + (dateTime.getDate().toString().padStart(2, '0'))
    return time
  }

  getCurrentTime(): string {
    let dateTime = new Date()
    let time = dateTime.getFullYear() + '-' + (dateTime.getMonth() + 1).toString().padStart(2, '0')
      + '-' + (dateTime.getDate().toString().padStart(2, '0')) + ' ' +
      (dateTime.getHours().toString().length == 1 ? '0' + dateTime.getHours() : dateTime.getHours()) + ':'
      + (dateTime.getMinutes().toString().length == 1 ? '0' + dateTime.getMinutes() : dateTime.getMinutes()) + ':'
      + (dateTime.getSeconds().toString().length == 1 ? '0'+ dateTime.getSeconds(): dateTime.getSeconds())
    return time
  }

  getHourAndMinute(): string {
    let dateTime = new Date()
    let time = (dateTime.getHours().toString().length == 1 ? '0' + dateTime.getHours() : dateTime.getHours()) + ':'
      + (dateTime.getMinutes().toString().length == 1 ? '0' + dateTime.getMinutes() : dateTime.getMinutes())
    return time
  }

  getDateAndWeek(): string {
    let dateTime = new Date()
    let weekDay = ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
    let time = ((dateTime.getMonth() + 1) < 10 ? ' ' + (dateTime.getMonth() + 1) : (dateTime.getMonth() + 1))
      + '月' + (dateTime.getDate() < 10 ? dateTime.getDate().toString() + '日' + '  ' : dateTime.getDate().toString() + '日' + ' ')+
    weekDay[dateTime.getDay()]
    return time
  }

  //上午、下午、晚上
  getTimePeriod(): string {
    let currentTime = new Date();
    let currentHour = currentTime.getHours();
    let period: string;
    if (currentHour < 12) {
      period = "上午";
    } else if (currentHour < 18) {
      period = "下午";
    } else {
      period = "晚上";
    };
    return period;
  }
}

let timeUtil = new TimeUtil();

export default timeUtil as TimeUtil;
