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

posted @ 2021-08-05 11:25  yuan_bao_er  阅读(2012)  评论(0编辑  收藏  举报