Js Date
来源:互联网 发布:linux安装apache服务器 编辑:程序博客网 时间:2024/06/05 07:05
<script type="text/javascript"> // var thedate = new Date(2013, 02, 06); // var thedate = new Date('2013,March, 06'); // alert(thedate.toLocaleDateString()) //1.2013-4-9 11:21:32 var today = new Date(); //2013年4月9日 星期二 // alert(today.toLocaleDateString()); //2013年4月9日 //alert(today.toLocaleTimeString()); var year = today.getFullYear(); var month = today.getMonth(); var date = today.getDate(); alert(year + '-' + month + '-' + date + " " + today.toLocaleTimeString()); //2.2013年4月9日 11点21分32秒 var hours = today.getHours(); var minute = today.getMinutes(); var Seconds = today.getSeconds(); alert(today.toLocaleTimeString() + " " + hours + '点' + minute + '分' + Seconds + '秒'); //3.2013年4月9日 上午11点21分32秒 //4.2013年4月9日 下午13点21分32秒 if(hours<12) { alert(today.toLocaleTimeString() + " " +"上午"+ hours + '点' + minute + '分' + Seconds + '秒'); } else{ alert(today.toLocaleTimeString() + " " + "下午" + hours + '点' + minute + '分' + Seconds + '秒'); } // 5.2011年6月23日 今天我已经毕业N年了 我已经毕业N月了 我已经毕业N天了// var thedate = new Date(2011,05,23);// var today = new Date();// alert(thedate.getTime()); // alert(today.getTime());// var milseconds = today - thedate;// alert('我们毕业' + Math.floor(milseconds / 1000 / 3600 / 24 / 365) + '年多了'); // alert('我们毕业' + (today.getFullYear() - thedate.getFullYear()) + '年了'); // alert('我们毕业' + today.getFullYear() - thedate.getFullYear()) * 12 + (today.getMonth() - thedate.getMonth() + '月了'); </script>