<!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8"> <title>JQ 日期Date()的使用</title> </head> <h3 style=" text-align: center; padding-top: 10px;" id="time"></h3> <h3 style=" text-align: center; padding-top: 6px;" id="weektime"></h3> <script type="text/javascript" src="jquery-1.10.1.min.js"></script> <script type="text/javascript"> $(function() { getWeekTime(); showDateInfo(); }); function getWeekTime(){ var now = new Date(); var today = new Array('星期日','星期一','星期二','星期三','星期四','星期五','星期六'); var week = today[now.getDay()]; var hh = now.getHours(); var mm = now.getMinutes(); var ss = now.getSeconds(); function getDateWeek(obj) { if (obj < 10) return "0" + obj; else return obj; } $("#time").text(getDateWeek(hh) + ":" + getDateWeek(mm) + ":" + getDateWeek(ss + 5)); $("#weektime").text(week+" "+getDateWeek(hh) + ":" + getDateWeek(mm)); } function showDateInfo(){ var myDate = new Date(); console.info("获取完整的年份:"+myDate.getFullYear()); console.info("获取当前月份(0-11,0代表1月):"+myDate.getMonth()); console.info("获取当前日(1-31):"+myDate.getDate()); console.info("获取当前星期X(0-6,0代表星期天):"+myDate.getDay()); console.info("获取当前时间(从1970.1.1开始的毫秒数):"+myDate.getTime()); console.info("获取当前小时数(0-23):"+myDate.getHours()); console.info("获取当前分钟数(0-59):"+myDate.getMinutes()); console.info("获取当前秒数(0-59):"+myDate.getSeconds()); console.info("获取当前毫秒数(0-999):"+myDate.getMilliseconds()); console.info("获取当前日期:"+myDate.toLocaleDateString()); } </script> </body> </html>
效果图: