<script> var myDate = new Date(); myDate.getYear(); //获取当前年份(2位) //alert(myDate.getYear()) //2009 myDate.getFullYear(); //获取完整的年份(4位,1970-????) //alert(myDate.getFullYear()); 2009 myDate.getMonth(); //获取当前月份(0-11,0代表1月) //alert(myDate.getMonth()); //7(实际是8月) myDate.getDate(); //获取当前日(1-31) //alert( myDate.getDate()); //13 myDate.getDay(); //获取当前星期X(0-6,0代表星期天) //alert(myDate.getDay()); //4 代表星期四 myDate.getTime(); //获取当前时间(从1970.1.1开始的毫秒数) myDate.getHours(); //获取当前小时数(0-23) //alert(myDate.getHours()); //9 代表9点 myDate.getMinutes(); //获取当前分钟数(0-59) //alert(myDate.getMinutes()); //45 分 myDate.getSeconds(); //获取当前秒数(0-59) //alert(myDate.getSeconds()); //40 秒数 myDate.getMilliseconds(); //获取当前毫秒数(0-999) myDate.toLocaleDateString(); //获取当前日期 var mytime=myDate.toLocaleTimeString(); //获取当前时间 //alert(mytime);//9:40:18 myDate.toLocaleString( ); //获取日期与时间 //alert( myDate.toLocaleString( )); //2009年8月13日 9:40:58 </script>
<script> function curDateTime() { var d = new Date(); var year = d.getYear(); var month = d.getMonth() + 1; var date = d.getDate(); var day = d.getDay(); var curDateTime = year; if (month > 9) curDateTime = curDateTime + month; else curDateTime = curDateTime + "0" + month; if (date > 9) curDateTime = curDateTime + date; else curDateTime = curDateTime + "0" + date; //myform.kprq.value = curDateTime; alert("当前日期"+curDateTime); document.getElementByIdx_x("date").value=curDateTime; } </script>
function curDateTime() { var d = new Date(); var year = d.getFullYear(); var month = d.getMonth() + 1; var date = d.getDate(); var day = d.getDay(); var curDateTime = year; if (month > 9) curDateTime = curDateTime + "-" + month; else curDateTime = curDateTime + "-0" + month; if (date > 9) curDateTime = curDateTime + "-" + date; else curDateTime = curDateTime + "-0" + date; return curDateTime; }
时间: 2024-11-05 23:29:24