简体   繁体   中英

Javascript invalid date first time

I have the following code. When the code runs the first time, it creates an invalid at the third line. When I debug the code, I found that the value of rowObj.$$lastModifiedTime is: 1385433554848 . When I put this number in jsfiddle.net and run the code, it creates the date object fine. Therefore, I am confused what's happening here. Am I missing something while debugging the code? I thank you for your time and effort in answering my question.

_getLastUpdated: function(rowObj) {
    if(rowObj && rowObj.$$lastModifiedTime) {
        var lastUpdated = new Date(parseInt(rowObj.$$lastModifiedTime, 10)); //this line gives invalid date the first time it runs
        lastUpdated.setMilliseconds(lastUpdated.getMilliseconds() + utils.Utils.instance().getServerTimeDifference(lastUpdated));
        var locale = utils.Utils.instance().getLocale();
        var dateFormatString = utils.Utils.instance().getLocaleDateString(locale)+" hh:MM:ss TT";
        var dateString = utils.Utils.instance().dateFormat(lastUpdated,dateFormatString);               
        return dateString;
    }
    return '';
}

the bug was in getServerTimeDifference(lastUpdated), it returned an object rather than a number. This entire piece of js is a dynamic script, so I would go back from a later function call dateFormat() into _getLastUpdated(). The date was created fine, but it was corrupted while doing the milliseconds addition. However, in the debugger, when I would go back from dateFormat() function call up in _getLastUpdated(), it showed me the lastUpdated object corrupted even at it's time of creation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM