2016.06.02【H5移动开发】VIP学员作业
发布于:2016-06-03 19:52
作业:
获取当前的日期
显示格式为:2016年06月02号 星期四
共有8条评论
正序查看
倒序查看
0
今日新帖
0
昨日新帖
42
帖子总数
推荐
换一组
72节H5交互动画精品课程,免费学习!
HTML5 2016-11-01 15:30
发布于:2016-06-03 19:52
作业:
获取当前的日期
显示格式为:2016年06月02号 星期四
0
今日新帖
0
昨日新帖
42
帖子总数
HTML5 2016-11-01 15:30
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>作业</title>
<script type="text/javascript">
var time = new Date();
var year = time.getFullYear();
var month = time.getMonth() + 1;
var date = time.getDate();
var originalDay = time.getDay();
var newDay;
switch (originalDay){
case 1:
newDay = "星期一";
break;
case 2:
newDay = "星期二"
break;
case 3:
newDay = "星期三";
break;
case 4:
newDay = "星期四";
break;
case 5:
newDay = "星期五";
break;
case 6:
newDay = "星期六";
break;
case 7:
newDay = "星期日";
break;
default:
newDay = "没有获取到星期,请重试";
break;
}
document.write(year + "年" + month + "月" + date + "日" + " " + newDay);
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title></title>
<script type="text/javascript">
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth()+1;
var dat = now.getDate();
var day = now.getDay();
var newDay;
if(month<10){
month="0"+month;
}
if(dat<10){
dat="0"+dat;
}
switch (day) {
case 0:
newDay = "星期日";
break;
case 1:
newDay = "星期一";
break;
case 2:
newDay = "星期二";
break;
case 3:
newDay = "星期三";
break;
case 4:
newDay = "星期四";
break;
case 5:
newDay = "星期五";
break;
case 6:
newDay = "星期六";
break;
default:
newDay="日期不正确";
break;
}
document.write(year+"年"+month+"月"+dat+"号"+" "+newDay);
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>作业</title>
<script type="text/javascript">
var time = new Date();
var year = time.getFullYear();
var originalMonth = time.getMonth() + 1;
var newMonth;
if (originalMonth < 10) {
newMonth = "0" + originalMonth;
} else{
newMonth = originalMonth;
}
var originalDate = time.getDate();
var newDate;
if (originalDate < 10) {
newDate = "0" + originalDate;
} else{
newDate = originalDate;
}
var originalDay = time.getDay();
var newDay;
switch (originalDay){
case 1:
newDay = "星期一";
break;
case 2:
newDay = "星期二"
break;
case 3:
newDay = "星期三";
break;
case 4:
newDay = "星期四";
break;
case 5:
newDay = "星期五";
break;
case 6:
newDay = "星期六";
break;
case 7:
newDay = "星期日";
break;
default:
newDay = "没有获取到星期,请重试";
break;
}
document.write(year + "年" + newMonth + "月" + newDate + "日" + " " + newDay);
</script>
</head>
<body>
</body>
</html>
getDay()的值应该是0-6吧
你们怎么都弄的那么复杂? 如果只是获取当前时间并输出的话,我这样就可以了吧?
var date = new Date;
document.write(date.getFullYear()+"年"+(date.getMonth()+1)+"月"+date.getDate()+"日");
不知道为什么,我的date.getDate();输出的结果不用加1,直接显示就是正常的。
var date = new Date;
var dat;
switch(date.getDay()){
case 1 :
dat = "星期一";
break;
case 2 :
dat = "星期二";
break;
case 3 :
dat = "星期三";
break;
case 4 :
dat = "星期四";
break;
case 5 :
dat = "星期五";
break;
case 6 :
dat = "星期六";
break;
case 7 :
dat = "星期日";
break;
default :
document.write("日期异常");
break;
}
document.write("今天是"+date.getFullYear()+"年"+(date.getMonth()+1)+"月"+date.getDate()+"日"+dat);
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>作业</title>
<script type="text/javascript">
var time = new Date();
var year = time.getFullYear();
var originalMonth = time.getMonth() + 1;
var newMonth;
if (originalMonth < 10) {
newMonth = "0" + originalMonth;
} else{
newMonth = originalMonth;
}
var originalDate = time.getDate();
var newDate;
if (originalDate < 10) {
newDate = "0" + originalDate;
} else{
newDate = originalDate;
}
var originalDay = time.getDay();
var newDay;
switch (originalDay){
case 1:
newDay = "星期一";
break;
case 2:
newDay = "星期二"
break;
case 3:
newDay = "星期三";
break;
case 4:
newDay = "星期四";
break;
case 5:
newDay = "星期五";
break;
case 6:
newDay = "星期六";
break;
case 0:
newDay = "星期日";
break;
default:
newDay = "没有获取到星期,请重试";
break;
}
document.write(year + "年" + newMonth + "月" + newDate + "日" + " " + newDay);
</script>
</head>
<body>
</body>
</html>
回复:2016.06.02【H5移动开发】VIP学员作业