JS根据日期得出星期几

function getweekday(date){

var weekArray = new Array("日", "一", "二", "三", "四", "五", "六");

var week = weekArray[new Date(date).getDay()];//注意此处必须是先new一个Date

return week;

}

 

例如:

1、获取系统时间并得出星期

   var week = weekArray[new Date().getDay()];

2、根据给定例如 

  var  da = '2017-12-12';

 var week = weekArray[new Date(da).getDay()];//注意此处必须是先new一个Date
 

你可能感兴趣的:(JS根据日期得出星期几)