javascriptのDate対象

2387 ワード

br>        "http://www.w3.org/TR/html4/loose.dtd">


Date



<br> //1. 1<br>// var date_obj=new Date();<br>// alert(date_obj)//Wed Jan 29 2020 16:44:15 GMT+0800 ( )<br>// alert(date_obj.toLocaleString())//2020/1/29 4:45:58<br> // ---- 1<br>// var date_obj1=new Date('2020/12/25 17:30');<br>// alert(date_obj1.toLocaleString())//2020/12/25 5:30:00<br> // 2<br>// var date_obj2=new Date('2020 12 25 17:30');<br>// alert(date_obj2.toLocaleString())//2020/12/25 5:30:00<br> //2. <br>// var date_obj3=new Date(5000);<br>// alert(date_obj3.toLocaleString());//1970/1/1 8:00:05<br>// alert(date_obj3.toUTCString());//Thu, 01 Jan 1970 00:00:05 GMT<br>// 3.date <br>// var date_obj4=new Date();<br>// alert(date_obj4.getFullYear());//2020<br>// alert(date_obj4.getMonth());//0<br>// alert(date_obj4.getDate());//29<br>// alert(date_obj4.getDay());//3<br>// alert(date_obj4.getHours());//17<br>// alert(date_obj4.getMinutes());//2<br>// alert(date_obj4.getSeconds());//28<br>// alert(date_obj4.getMilliseconds());//207<br> function getTime() {<br> var date_obj= new Date();<br> var year=date_obj.getFullYear();<br> var month=date_obj.getMonth()+1;<br> var day=date_obj.getDate();<br> var hour=date_obj.getHours();<br> var minute=date_obj.getMinutes();<br> var seconds=date_obj.getSeconds();<br> var week=date_obj.getDay();<br><br><br> return year+" "+month+" "+f(day)+" "+" "+hour+": "+minute+" :"+seconds+" "+num_week(week)<br>}<br> //Date :<br> alert(getTime());//2020 1 29 17: 34 :19 <br> function f(num) {<br> if (num<10){<br> return "0"+num;<br> }<br> return num;<br> }<br> function num_week(n) {<br> week=[" "," "," "," "," "," "," "];<br> return week[n]<br> }<br><br><br><br><br>