public static long getTimeDiff(Date fromDate, Date toDate, int type) {
        fromDate = (fromDate == null) ? new Date() : fromDate;
        toDate = (toDate == null) ? new Date() : toDate;
        long diff = toDate.getTime() - fromDate.getTime();
        
        switch(type) {
        case DIFF_MILLSECOND:
            break;
            
        case DIFF_SECOND:
            diff /= 1000;
            break;
            
        case DIFF_MINUTE:
            diff /= 1000 * 60;
            break;
            
        case DIFF_HOUR:
            diff /= 1000 * 60 * 60;
            break;
            
        case DIFF_DAY:
            diff /= 1000 * 60 * 60 * 24;
            break;
            
        case DIFF_MONTH:
            diff /= 1000 * 60 * 60 * 24 * 30;
            break;

        case DIFF_YEAR:
            diff /= 1000 * 60 * 60 * 24 * 365;
            break;
            
        default:
            diff = 0;
            break;
        }
        
        return diff;
    }