求js详细时间代码,年月日星期时分(秒),阴历日期
function RunGLNL(){
var today=new Date();
var d=new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
B. JS计算系统当前日期是星期几的几种方法
方法一:
// 计算系统当前是星期几var str = "今天是星期" + "日一二三四五六".charat(new Date().getDay());
方法二:
var a = new array("日", "一", "二", "三", "四", "五", "六");var week = new Date().getDay();var str = "今天是星期"+ a[week];
alert(str);
方法三:
var str = "今天是星期";var week = new Date().getDay();switch (week) { case 0 :
str += "日"; break; case 1 :
str += "一"; break; case 2 :
str += "二"; break; case 3 :
str += "三"; break; case 4 :
str += "四"; break; case 5 :
str += "五"; break; case 6 :
str += "六"; break;
}
alert(str);
方法四:
var str = "";var week = new Date().getDay();if (week == 0) {
str = "今天是星期日";
} else if (week == 1) {
str = "今天是星期一";
} else if (week == 2) {
str = "今天是星期二";
} else if (week == 3) {
str = "今天是星期三";
} else if (week == 4) {
str = "今天是星期四";
} else if (week == 5) {
str = "今天是星期五";
} else if (week == 6) {
str = "今天是星期六";
}
alert(str);
C. javascript给定了日期如何获得星期几
1、这可以用JavaScript的Date对象的getDay方法。
如:获取当天是星期几,则为:new Date().getDay();
//返回回0-6,0对应星期天,1-6对应星期一到星期六答
2、如果想给定某个时间是星期几,则应该把字符串转化为Date。
如:new Date('2015-09-27').getDay();//将返回0,表示星期天
3、具体,可以参见http://www.w3school.com.cn/jsref/jsref_obj_date.asp里对date的介绍
D. 用js实现日期时间格式化
效果图:
源码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"亮野巧>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div>
<span id="date"></span> <br>
<span id="week"></span>
</div>
<script>
var showDate = document.getElementById('date'); // 获取页面元素
var showWeek = document.getElementById('week'); 敬键// 获取页面元素
var time = new Date();
var year = time.getFullYear(); //获取年份
var month = correctDate(time.getMonth() + 1); //获取月份
var day = correctDate(time.getDate()); //获取日期
var date = "今天是" + year + "年" + month + "月" + day + "日";
var week = time.getDay(); // 获取星期几,返回的是0/1/2/3/4/5/6 0代表周日
var weeks = [ "星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
var toWeek = weeks[week]; // 获取今日星期
showDate.innerHTML = date; // 将日期显示在页面
showWeek.innerHTML = toWeek; // 将星期显示在页面
/* 这是一个规范数字的函数:
当时间小于10时,在数字前面加上0,统一都是用两个数字表示,
比如3月5日就显示03月05日
*/
function correctDate(date){
if(date<10){
脊衫 return '0'+date;
}
return date;
}
</script>
</body>
</html>