刚学javascript遇到的问题——怎么算…
2016-06-30 17:40
441 查看
function weekNo() {
var totalDays = 0;
now = new Date();
years=now.getYear()
if (years < 1000)
years+=1900
var days = new Array(12);
days[0] = 31;
days[2] = 31;
days[3] = 30;
days[4] = 31;
days[5] = 30;
days[6] = 31;
days[7] = 31;
days[8] = 30;
days[9] = 31;
days[10] = 30;
days[11] = 31;
if
(Math.round(now.getYear()/4) == now.getYear()/4) {
days[1] = 29
}else{
days[1] = 28
}
if (now.getMonth() == 0) {
totalDays = totalDays + now.getDate();
}else{
var
curMonth = now.getMonth();
for
(var count = 1; count <= curMonth; count++) {
totalDays = totalDays +
days[count - 1];
}
totalDays = totalDays + now.getDate();
}
var week =
Math.round(totalDays/7);
return week;
}
function formatDate(date) {
return date.getFullYear() + "." + date.getMonth() + "." +
date.getDate();
}
function firstAndFinalDayStr() {
var now = new Date();
var weeoDay = now.getUTCDay();
var firstDay = new Date();
firstDay.setDate(now.getDate() - weeoDay + 1);
var finalDay = new Date();
finalDay.setDate(now.getDate() + (7 - weeoDay));
return formatDate(firstDay) +"~" + formatDate(finalDay)+"
"
}
function run() {
var info = "", no = weekNo();
info += firstAndFinalDayStr();
info += document.getElementByIdx_x("weekInfo").innerHTML =
info;
}
run();
document.write("第 "+weekNo()+"周("+years+"年)")
// -->
看目前网上的时间显示,并没有这种显示的代码,写出来,希望能给大家更多的帮助。
更多信息,请点击:http://blog.sina.com.cn/u/2308368145
var totalDays = 0;
now = new Date();
years=now.getYear()
if (years < 1000)
years+=1900
var days = new Array(12);
days[0] = 31;
days[2] = 31;
days[3] = 30;
days[4] = 31;
days[5] = 30;
days[6] = 31;
days[7] = 31;
days[8] = 30;
days[9] = 31;
days[10] = 30;
days[11] = 31;
if
(Math.round(now.getYear()/4) == now.getYear()/4) {
days[1] = 29
}else{
days[1] = 28
}
if (now.getMonth() == 0) {
totalDays = totalDays + now.getDate();
}else{
var
curMonth = now.getMonth();
for
(var count = 1; count <= curMonth; count++) {
totalDays = totalDays +
days[count - 1];
}
totalDays = totalDays + now.getDate();
}
var week =
Math.round(totalDays/7);
return week;
}
function formatDate(date) {
return date.getFullYear() + "." + date.getMonth() + "." +
date.getDate();
}
function firstAndFinalDayStr() {
var now = new Date();
var weeoDay = now.getUTCDay();
var firstDay = new Date();
firstDay.setDate(now.getDate() - weeoDay + 1);
var finalDay = new Date();
finalDay.setDate(now.getDate() + (7 - weeoDay));
return formatDate(firstDay) +"~" + formatDate(finalDay)+"
"
}
function run() {
var info = "", no = weekNo();
info += firstAndFinalDayStr();
info += document.getElementByIdx_x("weekInfo").innerHTML =
info;
}
run();
document.write("第 "+weekNo()+"周("+years+"年)")
// -->
看目前网上的时间显示,并没有这种显示的代码,写出来,希望能给大家更多的帮助。
更多信息,请点击:http://blog.sina.com.cn/u/2308368145
相关文章推荐
- JS数组,字典
- cefsharp 运行环境与JS
- JavaScript:闭包
- JS正则表达式验证账号、手机号、电话和邮箱
- js date时间操作(二)
- jvm命令之jstat
- seaJs 使用
- jstl标签中的fn与fmt标签的用法
- JavaScript异步机制
- 推荐一个图片管理的html模版和简单的js交互
- Ajax加载HTML、XML、JSON对比分析
- iOS中JavaScript和OC交互
- jsonp
- 阻止js事件冒泡的例子(cancelBubble 、stopPropagation)
- 浏览器探针--JavaScript
- js 获取日期xxxx-xx-xx格式
- 如何将JS的变量传递给highcharts中series:data,感觉都是基于JS,怎么就不行呢?
- EL和JSTL
- 原生javascript控制兄弟节点
- 27、理解js的继承机制(转载自阮一峰)