求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>