نمایش دو روز ابتدا و انتهای هفته فعلی (با javascript)
این کد برای نمایش دو روز ابتدا و انتهای هفته فعلی به کار می رود :
کدها :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="JavaScript">
function formatDate(date) {
var mymonth = date.getMonth()+1;
var myweekday = date.getDate();
return (mymonth + "/" + myweekday);
}
function printWeek() {
var now = new Date();
var nowDayOfWeek = now.getDay();
var nowDay = now.getDate();
var nowMonth = now.getMonth();
var nowYear = now.getYear();
nowYear += (nowYear < 2000) ? 1900 : 0;
var weekStartDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek);
var weekEndDate = new Date(nowYear, nowMonth, nowDay + (6 - nowDayOfWeek));
document.write("Current Week: " + formatDate(weekStartDate) + " - " + formatDate(weekEndDate));
}
</script>
</head>
<body>
<script>
printWeek();
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="JavaScript">
function formatDate(date) {
var mymonth = date.getMonth()+1;
var myweekday = date.getDate();
return (mymonth + "/" + myweekday);
}
function printWeek() {
var now = new Date();
var nowDayOfWeek = now.getDay();
var nowDay = now.getDate();
var nowMonth = now.getMonth();
var nowYear = now.getYear();
nowYear += (nowYear < 2000) ? 1900 : 0;
var weekStartDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek);
var weekEndDate = new Date(nowYear, nowMonth, nowDay + (6 - nowDayOfWeek));
document.write("Current Week: " + formatDate(weekStartDate) + " - " + formatDate(weekEndDate));
}
</script>
</head>
<body>
<script>
printWeek();
</script>
</body>
</html>
دسته بندی
کدهای آماده برای زمان و تاریخ
نظرات 0 0 0