开发者

Javascript not able to evaluate expression

I m trying to calculate a day diff in Javascript to apply some value. The first expression

if subs_start

is working fine, but the开发者_Python百科 second one

subs_end

is not working, same goes with

subs_mid

Code:

var subs_start = 0;
var subs_mid = 0;
var subs_end = 0;               
var dayDiff = (end_year*365 + end_mon * 30 + end_day) 
            - (start_year*365 + start_mon* 30 + start_day);
var oneDay=1000*60*60*24;
var oneHour = 1000*60*60;
var timeDiff = endDate.getTime() - startDate.getTime();
var hourDiff = timeDiff/oneHour;
var start_rem_hour = 24 - start_hour*1;

$.each(subsistence, function(id,subs){

    if(subs.start <= start_rem_hour && start_rem_hour < subs.end ){
        subs_start = subs.rate;
    }                   
    alert('T' + end_hour);

    if(subs.start <= end_hour && end_hour < subs.end ){
        subs_end = subs.rate;
        alert ('e ' + subs_end);
    }

    if(dayDiff > 2){
        if(subs.start >= 10){
            subs_mid = subs.rate * (dayDiff - 2);
            alert ('m ' + subs_mid);
        }
    }

}); 

var subs_allow = subs_start*1 + subs_mid*1 + subs_end*1 ;


I m finally able to find the answer. I need to multiple start_rem_hour and end_hour with 1 to convert into int. It seems js is taking them as string and when i multiply with 1 it gets into integer scope.


Not sure what is being asked for.

For DateTime calculations in javascript I would recommend Datejs library:

http://www.datejs.com/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜