如何在javascript中获得一周的价值,昨天,一个月,一个月,一个月和一年?

时间:2016-06-09 10:37:43

标签: javascript datetime

function filtervalue(filterval,contactid,contactname,contactuserid,device)
        {

            var time1 = '00:01:00';
            if(filterval=='1')
            {

            $("#customsearch").show();  
            }
            else
            {

                var today = new Date();
                var dd = today.getDate();
                var mm = today.getMonth()+01; //January is 0!
                var yyyy = today.getFullYear();

            if(dd<10) {
                dd='0'+dd
                dd = dd-7
            } 

            if(mm<10) {
                mm='0'+mm
            } 
            if(filterval=='2')
            {
              //yesterday case

                dd=dd-1;
            today = yyyy+'-'+mm+'-'+dd+' '+time1;
                //submitfilterdata(today,contactid);
            alert(today);
                since_msg_count['c'+contactid] = today;
                myFunction(today,contactid,contactname,contactuserid,device);
            }   
                if(filterval==3)
                {
               //one week case
                dd= dd-7;
                    today = yyyy+'-'+mm+'-'+dd+' '+time1;
                    alert(today);
                    //submitfilterdata(today,contactid);
                    since_msg_count['c'+contactid] = today;
                    myFunction(today,contactid,contactname,contactuserid,device);

                }
                if(filterval==4)
                {
                   //3 months case

                    today = yyyy+'-'+mm+'-'+dd;
                    var date = new Date(today);
                    date.setMonth(date.getMonth() - 3);

                    var dd = date.getDate();
                    var mm = date.getMonth()+01; //January is 0!
                    var yyyy = date.getFullYear();
                    today = yyyy+'-'+mm+'-'+dd+' '+time1;
                    alert(today);
                    //submitfilterdata(today,contactid);
                    since_msg_count['c'+contactid] = today;
                    myFunction(today,contactid,contactname,contactuserid,device);
                }
                if(filterval==5)
                {
//6 months case
                today = yyyy+'-'+mm+'-'+dd;
                var date = new Date(today);
                date.setMonth(date.getMonth() - 6);

                var dd = date.getDate();
                var mm = date.getMonth()+01; //January is 0!
                var yyyy = date.getFullYear();
                today = yyyy+'-'+mm+'-'+dd+' '+time1;
                    //submitfilterdata(today,contactid);
                                alert(today);
                    since_msg_count['c'+contactid] = today;
                myFunction(today,contactid,contactname,contactuserid,device);
                }
                if(filterval==6)
                {
//one year case
                today = yyyy+'-'+mm+'-'+dd;
                    var date = new Date(today);
                date.setMonth(date.getMonth() - 12);

                var dd = date.getDate();
                var mm = date.getMonth()+01; //January is 0!
                var yyyy = date.getFullYear();
                today = yyyy+'-'+mm+'-'+dd+' '+time1;;
                    alert(today);   
                    //submitfilterdata(today,contactid);
                    since_msg_count['c'+contactid] = today;
                myFunction(today,contactid,contactname,contactuserid,device);
                }
                if(filterval==7)
                {
                    since_msg_count['c'+contactid] = '';
                    //submitfilterdata('',contactid);
                myFunction('',contactid,contactname,contactuserid,device)
                }


        }

    }
  

我正在使用上述功能获得昨天,一周,一个   从当前日期起的月,3个月,6个月和一年的价值但是   它给我错了。我需要像2016-06-1 00:01:00这样的格式   让我知道我的代码中的错误是什么,以及是否还有其他问题   我可以用来解决这个问题

0 个答案:

没有答案