1.js 怎么取到时间戳里面的月份?
复制代码 代码示例:
方法1:
var timestamp = date.parse(new date());
结果:1280977330000
方法2:
var timestamp = (new date()).valueof();
结果:1280977330748
方法3:
var timestamp=new date().gettime();
结果:1280977330748
第一种:获取的时间戳是把毫秒改成000显示,
第二种和第三种是获取了当前毫秒的时间戳。
附,js时间函数
1,取得当前时间:
var date=new date();
2,已知年、月、日转换成日期型的数据:
复制代码 代码示例:
var applydate = document.domainexceptionform.applydate.value;
applydate = applydate.split("t")[0];
var applyyear = applydate.split("-")[0];
var applymonth = applydate.split("-")[1]-1;
var applyday = applydate.split("-")[2];
var applydate1 = new date(applyyear,applymonth,applyday );
3,比较两日期相差的天数是否大于5:
parseint((date-applydate1) / (1000 * 60 * 60 * 24)) >= 5
2.怎么用JS代码自定义的日历呢?
html xmlns= head title无标题页-学无忧()/titlescript language=javascriptvar months = new Array(一, 二, 三,四, 五, 六, 七, 八, 九,十, 十一, 十二);//定义月份var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31,30, 31, 30, 31); //定义每月的天数var days = new Array(日,一, 二, 三,四, 五, 六);//定义星期几var classTemp;var today=new getToday();var year=today。
year; //获取年份var month=today。month; //获取月份var newCal; //用来获取指定年月中的天数function getDays(month, year){ if (1 == month) return ((0 == year % 4) (0 != (year % 100))) ||(0 == year % 400) ? 29 : 28; else return daysInMonth[month];}//获取今天的年、月、日function getToday() { this。
now = new Date(); this。year = this。
now。getFullYear(); this。
month = this。now。
getMonth(); this。day = this。
now。getDate();}//定义日历表的显示方法function Calendar() { newCal = new Date(year,month,1); today = new getToday(); var day = -1; var startDay = newCal。
getDay(); var endDay=getDays(newCal。getMonth(), newCal。
getFullYear()); var daily = 0; if ((today。year == newCal。
getFullYear()) (today。 month == newCal。
getMonth())) { day = today。day; } var caltable = document。
all。caltable。
tBodies。calendar; var intDaysInMonth =getDays(newCal。
getMonth(), newCal。getFullYear()); for (var intWeek = 0; intWeek caltable。
rows。length;intWeek++) for (var intDay = 0;intDay caltable。
rows[intWeek]。cells。
length;intDay++) { var cell = caltable。rows[intWeek]。
cells[intDay]; var montemp=(newCal。getMonth()+1)10?(0+(newCal。
getMonth()+1)):(newCal。getMonth()+1); if ((intDay == startDay) (0 == daily)){ daily = 1;} var daytemp=daily10?(0+daily):(daily); var d=+newCal。
getFullYear()+-+montemp+-+daytemp+; if(day==daily) cell。className=DayNow; else if(intDay==6) cell。
className = DaySat; else if (intDay==0) cell。 className =DaySun; else cell。
className=Day; if ((daily 0) (daily = intDaysInMonth)) { cell。innerText = daily; daily++; } else { cell。
className=CalendarTD; cell。innerText = ; } } document。
all。year。
value=year; document。all。
month。value=month+1;}//实现月份向前翻页的方法function subMonth(){ if ((month-1)0) { month=11; year=year-1; } else { month=month-1; } Calendar();}//实现月份向后翻页的方法function addMonth(){ if((month+1)11) { month=0; year=year+1; } else { month=month+1; } Calendar();}//判断用户自己输入的年份和月份function setDate() { if (document。
all。month。
value1||document。all。
month。value12) { alert(月的有效范围在1-12之间!); return; } year=Math。
ceil(document。all。
year。value); month=Math。
ceil(document。all。
month。value-1); Calendar();}//设置按钮的样式function buttonOver(){var obj = window。
event。srcElement;obj。
runtimeStyle。 cssText = background-color:#FFFFFF;}function buttonOut(){var obj = window。
event。srcElement;window。
setTimeout(function(){obj。 runtimeStyle。
cssText = ;},300);}/scriptStyleInput {font-family: verdana;font-size: 9pt;text-decoration: none;background-color: #FFFFFF;height: 20px;border: 1px solid #666666;color:#000000;}。 Calendar {font-family: verdana;text-decoration: none;width: 170;background-color: #C0D0E8;font-size: 9pt;border:0px dotted #1C6FA5;}。
CalendarTD {font-family: verdana;font-size: 7pt;color: #000000;background-color:#f6f6f6;height: 20px;width:11%;text-align: center;}。 Title {font-family: verdana;font-size: 11pt;font-weight: normal;height: 24px;text-align: center;color: #333333;text-decoration: none;background-color: #A4B9D7;border-top-width: 1px;border-right-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-bottom-style:1px;border-top-color: #999999;border-right-color: #999999;border-bottom-color: #999999;border-left-color: #999999;}。
Day {font-family: verdana;font-size: 7pt;color:#243F65;background-color: #E5E9F2;height: 20px;width:11%;text-align: center;}。 DaySat {font-family: verdana;font-size: 7pt;color:#FF0000;text-decoration: none;background-color:#E5E9F2;text-align: center;height: 18px;width: 12%;}。
DaySun {font-family: verdana;font-size: 7pt;color: #FF0000;text-decoration: none;background-color:#E5E9F2;text-align: center;height: 18px;width: 12%;}。 DayNow {font-family: verdana;font-size: 7pt;font-weight: bold;color: #000000;background-color: #FFFFFF;height: 20px;text-align: center;}。
DayTitle {font-family: verdana;font-size: 9pt;color: #000000;background-color: #C0D0E8;height: 20px;width:11%;text-align: center;}。 DaySatTitle {font-family: verdana;font-size: 9pt;color:#FF0000;text-decoration: none;。
3.JS实现取当月的最后一天代码怎么写呢?
html xmlns= headtitle标题页-学无忧()/titlescript language=javascriptfunction getLastDay(year,month){var new_year = year; //取当前的年份var new_month = month++;//取下一个月的第一天,方便计算(最后一天不固定)if(month12) //如果当前大于12月,则年份转到下一年{ new_month -=12; //月份减 new_year++; //年份增}var new_date = new Date(new_year,new_month,1); //取当年当月中的第一天return (new Date(new_date。
getTime()-1000*60*60*24))。 getDate();//获取当月最后一天日期}/scriptbody input id=Button1 type=button value=取2007年5月的最后一天 onclick=alert(getLastDay(2007,5)) //body/html。
4.js获取某年某月的哪些天是周六和周日
<p id="text"></p>
<script type="text/javascript">
function time(y,m){
var tempTime = new Date(y,m,0);
var time = new Date();
var saturday = new Array();
var sunday = new Array();
for(var i=1;i<=tempTime.getDate();i++){
time.setFullYear(y,m-1,i);
var day = time.getDay();
if(day == 6){
saturday.push(i);
}else if(day == 0){
sunday.push(i);
}
}
var text = y+"年"+m+"月份"+"<br />"
+"周六:"+saturday.toString()+"<br />"
+"周日:"+sunday.toString();
document.getElementById("text").innerHTML = text;
}
time(2014,7);
</script>
5.在JS中我有多少秒,我怎么把他转为时间格式
function gettime(){ now = new Date();//得到当前时间y= now.getYear();//得到年份yy=\"0\"+(now.getMonth()+1); //得到月d=\"0\"+(now.getDay());??h=\"0\"+now.getHours(); m=\"0\"+now.getMinutes(); s=\"0\"+now.getSeconds(); if(yy>9){??yy= now.getYear();}if(d>9){??d=now.getDay()+12; }if(h>9){??h=now.getHours()} if(m>9){??m=now.getMinutes()} if(s>9){??s=now.getSeconds()} timestr=y+\"-\"+yy+\"-\"+d+\" \"+h+\":\"+m+\":\"+s;return timestr;}因为有时区的差异,所以要相应的调整,年月日时分秒都得到后,要得到**:**时间就简单了,直接连接就可以了。
转载请注明出处JS代码网 » 在js中调取任意份的单月月历(js怎么取到时间戳里面的月份?)