js关于new Date() 日期格式
下面是关于Date的对象
var oDay = new Date(); oDay.getYear(); //当前年份 oDay.getFullYear(); //完整的年月日(xx年,xx月,xx日) oDay.getMonth(); //当前的月份(0-11,0代表1月) // 获取当前的月份是oDay.getMonth()+1;
oDay.getDate(); //当前的日(1-31) oDay.getDay(); //当前的星期X(0-6,0代表星期天) oDay.getTime(); //当前的时间(从1970.1.1开始的毫秒数) oDay.getHours(); //当前的小时数(0-23) oDay.getMinutes(); //当前的分钟数(0-59) oDay.getSeconds(); //当前的秒数(0-59) oDay.getMilliseconds(); //当前的毫秒数(0-999) oDay.toLocaleDateString(); //当前的日期 var oTime=oDay.toLocaleTimeString(); //当前的时间
oDay.toLocaleString( ); //日期与时间
下面是关于获取时间的几个小例子:
//本月有多少天
var oDate=new Date();
oDate.setMonth(oDate.getMonth()+1);
oDate.setDate(0);
alert(oDate.getDate());
//本月第一天是周几
ar oDate=new Date();
oDate.setDate(1);
alert(oDate.getDay())
//本月最后一天是周几
var oDate=new Date();
oDate.setMonth(oDate.getMonth()+1);
oDate.setDate(0);
alert(oDate.getDay());
浙公网安备 33010602011771号