计数月 [英] Count on the month

查看:156
本文介绍了计数月的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我工作的程序,我用它来添加小时的员工。但现在我有一个问题,我已经设置日期自动上周一星期一(28-09-2015星期一,29-09-2015星期二等),但是当我在月底,它



在这里您可以看到一张图片:





当我们从9月30日到10月1日,它停止工作。
这是我使用的脚本

  $(document).ready(function(){
function getMonday(d)
{
var day = d.getDay();
diff = d.getDate() - day + -6;
return new Date(d.setDate (diff));
}

var day = getMonday(new Date());
var month = day.getMonth()+ 1;

for(var i = 0; i <7; i ++)
{
$('[name =start_day'+ i +'')。val(day.getDate );
$('[name =start_month'+ i +'')。val(month);
}

这是我用于日期的Javascript:



< script src =https ://code.jquery.com/jquery-1.9.1.min.js>< / script>



请告诉我我在做什么错误?

解决方案

/ p>

  $(document).ready(function(){
function getMonday(d)
{
var day = d.getDay();
diff = d.getDate() - day + -6;
return new Date(d.setDate(diff));
}

var day = getMonday(new Date());
var month = day.getMonth()+ 1;

for(var i = 0; i <7; i ++)
{
var thisDate = new Date(day.getTime()+(24 * 60 * 60 * 1000 * i));
$('[name =start_day'+ i +'')。val(thisDate.getDate());
$('[name =start_month'+ i +'')。val(thisDate.getMonth()+ 1);
}


I have a program which I work with, I use it to add hours of the employees. But now I have a problem, I have set the date automatically on the Monday of past week (28-09-2015 Monday, 29-09-2015 Tuesday etc.), but when I'm at the end of the month, it doesn't work anymore.

Here you can see a picture:

When we go from 30 September to 1 October, it stopped working. This is the script I use

$(document).ready(function() {
function getMonday(d) 
{
var day = d.getDay();
diff = d.getDate() - day + -6; 
return new Date(d.setDate(diff));
}

var day = getMonday(new Date());
var month = day.getMonth()+1;

for(var i = 0; i < 7; i++)
{
$('[name="start_day'+i+'"').val(day.getDate()+i);
$('[name="start_month'+i+'"').val(month);
}

and this is the Javascript I use for the date:

<script src = "https://code.jquery.com/jquery-1.9.1.min.js"> </script>

Can anybody please tell me what I'm doing wrong?

解决方案

Try it like this. Increase the time by 24 hours...

$(document).ready(function() {
function getMonday(d) 
{
var day = d.getDay();
diff = d.getDate() - day + -6; 
return new Date(d.setDate(diff));
}

var day = getMonday(new Date());
var month = day.getMonth()+1;

for(var i = 0; i < 7; i++)
{
var thisDate = new Date(day.getTime() + (24 * 60 * 60 * 1000 * i)); 
$('[name="start_day'+i+'"').val(thisDate.getDate());
$('[name="start_month'+i+'"').val(thisDate.getMonth() + 1);
}

这篇关于计数月的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆