1. 程式人生 > >年月份轉換成大寫的星期

年月份轉換成大寫的星期

function getWeek(dateString) {
  let date;
  if (dateString == null || typeof dateString == "undefined") {
    date = new Date();
  } else {
    let dateArray = dateString.split(/[-./]/);
    date = new Date(dateArray[0], parseInt(dateArray[1] - 1), dateArray[2]);
  }
  console.log(date.getDay());  //得到具體的星期幾的數字
  return "星期" + "日一二三四五六".charAt(date.getDay());  //索引取字串中的值
}

let dateNow = '2018.10.10';
let week = getWeek(dateNow);
console.log(week)