我从服务器上取日期,需要在html页面上显示。 日期每天都会改变。但星期六星期天星期日将显示星期五。
再次从下周一开始,它会定期约会,请帮忙 我正在考虑展示。 getServerTime用于请求服务器日期。
HTML:
<span id="currentdate"></span>
JavaScript的:
var weekday = ["Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"
];
var allmonth = new Array(12);
allmonth[0] = "january";
allmonth[1] = "february";
allmonth[2] = "march";
allmonth[3] = "april";
allmonth[4] = "may";
allmonth[5] = "june";
allmonth[6] = "july";
allmonth[7] = "august";
allmonth[8] = "september";
allmonth[9] = "october";
allmonth[10] = "november";
allmonth[11] = "december";
function getServerTime() {
return $.ajax({
async: false
}).getResponseHeader('Date');
}
var st = getServerTime();
var date = new Date(st);
//alert(date+"this is server date");
var day = weekday[date.getDay()];
var currentdate = date.getDate();
var currentmonth = allmonth[date.getMonth()];
var currentyear = date.getFullYear();
var fulldate = currentdate + "-" + currentmonth + "-" + currentyear;
var fridayday = "";
if (day == 'Monday' || day == 'Tuesday' || day == 'Thursday' ||
day == 'Wednesday') {
$("#currentdate").html(fulldate);
alert("this is working day");
} else if (day == "Friday") {
fridayday = fulldate;
alert("this is friday");
alert(fridayday + "fridayday date inside if");
$("#currentdate").html(fulldate);
} else if (day == 'Saturday' || day == 'Sunday') {
$("#currentdate").html(fridayday);
alert("this is not a working day");
}
alert(fridayday + "fridayday date out side if");
答案 0 :(得分:0)
从我通过阅读你的问题的理解,你想在星期五,星期六和星期日显示同样的事情。那你为什么不在你的else if
陈述中实施周六和周日呢?
即:
else if (day == "Friday" || day == "Saturday" || day == "Sunday") {
fridayday = fulldate;
alert("this is " + day);
alert(fridayday + "fridayday date inside if");
$("#currentdate").html(fulldate);
}