所以我正在从服务中检索两个值:
start date/time: 1970-06-08T23:00:00Z
end date/time: 1970-06-13T07:00:00Z
例如:tue-sat 08:00 - 16:00 | sun-thur 09:00 - 17:00
任何想法如何解决这个问题?
答案 0 :(得分:1)
您可以使用getUTCDay()
:
<p id="demo"></p>
<script>
function setDayRange() {
var dstart = new Date('1970-06-08');
var dend = new Date('1970-06-13');
var weekday = new Array(7);
weekday[0] = "Sunday";
weekday[1] = "Monday";
weekday[2] = "Tuesday";
weekday[3] = "Wednesday";
weekday[4] = "Thursday";
weekday[5] = "Friday";
weekday[6] = "Saturday";
var nstart = weekday[dstart.getUTCDay()];
var nend = weekday[dend.getUTCDay()];
document.getElementById("demo").innerHTML = nstart + ' to ' + nend;
}
</script>
现在只需用一些日期字符串替换输入'1970-06-08'
和'1970-06-13'
。
来源(已修改):http://www.w3schools.com/jsref/jsref_getutcday.asp
希望它有所帮助;)