javascript取得日、時間、分、曜日
2016 ワード
1、取得日曜日(出力:2015年6月25日木曜日)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>TT</title>
</head>
<body>
<script>
function syncTime(){
var mydate = new Date();
var week;
switch (mydate.getDay()){
case 1: week=" "; break;
case 2: week=" "; break;
case 3: week=" "; break;
case 4: week=" "; break;
case 5: week=" "; break;
case 6: week=" "; break;
default: week=" ";
}
var str = "" + mydate.getFullYear() + " " + (mydate.getMonth() + 1) + " " + mydate.getDate() + " " + week;
return str;
}
console.log(syncTime());
</script>
</body>
</html>
2、取得日付時間分(出力:2015-06-25 02:03)<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
function CurentTime()
{
var now = new Date();
var year = now.getFullYear(); //
var month = now.getMonth() + 1; //
var day = now.getDate(); //
var hh = now.getHours(); //
var mm = now.getMinutes(); //
var clock = year + "-";
if(month < 10)
clock += "0";
clock += month + "-";
if(day < 10)
clock += "0";
clock += day + " ";
if(hh < 10)
clock += "0";
clock += hh + ":";
if (mm < 10) clock += '0';
clock += mm;
return(clock);
}
console.log(CurentTime());
</script>
</body>
</html>