Example usage for java.text ParseException printStackTrace

List of usage examples for java.text ParseException printStackTrace

Introduction

In this page you can find the example usage for java.text ParseException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:ait.ffma.utils.KeyAndFrequency.java

public static KeyAndFrequency fromJson(JSONObject obj, Class clazz) {
    try {//  www. ja va2s. com
        if (clazz.equals(Integer.class)) {
            KeyAndFrequency kf = new KeyAndFrequency(obj.getInt(KEY_FLD), obj.getInt(FREQ_FLD));
            return kf;
        }
        if (clazz.equals(String.class)) {
            KeyAndFrequency kf = new KeyAndFrequency(obj.get(KEY_FLD), obj.getInt(FREQ_FLD));
            return kf;
        }

        if (clazz.equals(Date.class)) {
            KeyAndFrequency kf = null;
            try {

                kf = new KeyAndFrequency(format.parse(obj.getString(KEY_FLD)), obj.getInt(FREQ_FLD));
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return kf;
        }
    } catch (JSONException e) {

    }
    return null;
}

From source file:mobile.tiis.appv2.helpers.Utils.java

public static String convertToParamDateFormat(String dateStr) {
    if (isStringNotBlank(dateStr)) {
        SimpleDateFormat fromDateFormat = new SimpleDateFormat(DEFAULT_DATE_PATTERN);
        SimpleDateFormat toDateFormat = new SimpleDateFormat(PARAM_DATE_PATTERN);
        try {// ww  w .  ja  va  2s  .c  om
            Date date = fromDateFormat.parse(dateStr);
            return toDateFormat.format(date);
        } catch (ParseException ex) {
            ex.printStackTrace();
        }
    }

    return null;
}

From source file:mobile.tiis.appv2.helpers.Utils.java

public static String convertToParamDate(String dateStr) {
    if (isStringNotBlank(dateStr)) {
        SimpleDateFormat fromDateFormat = new SimpleDateFormat(PARAM_DATE_PATTERN);
        SimpleDateFormat toDateFormat = new SimpleDateFormat(DEFAULT_DATE_PATTERN);
        try {//from   w  ww.jav a  2  s . c  om
            Date date = fromDateFormat.parse(dateStr);
            return toDateFormat.format(date);
        } catch (ParseException ex) {
            ex.printStackTrace();
        }
    }

    return null;
}

From source file:com.teamsun.framework.util.DateUtil.java

/**
 * This method converts a String to a date using the datePattern
 * /*from   w  w  w. ja v  a 2  s.  co m*/
 * @param strDate the date to convert (in format yyyy-MM-dd)
 * @return a date object
 * 
 * @throws ParseException
 */
public static Date convertStringToDate(String strDate) throws ParseException {
    Date aDate = null;

    try {
        if (log.isDebugEnabled()) {
            log.debug("converting date with pattern: " + datePattern);
        }

        aDate = convertStringToDate(datePattern, strDate);
    } catch (ParseException pe) {
        log.error("Could not convert '" + strDate + "' to a date, throwing exception");
        pe.printStackTrace();
        throw new ParseException(pe.getMessage(), pe.getErrorOffset());

    }

    return aDate;
}

From source file:com.naver.mage4j.core.util.PhpDateUtils.java

public static Calendar CalendarFromString(String date, String format) {
    Calendar cal = Calendar.getInstance();

    try {/*from  w  w w  . j  a v  a2  s  . c o  m*/
        SimpleDateFormat formatter = new SimpleDateFormat(format);
        cal.setTime(formatter.parse(date));
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return cal;
}

From source file:Main.java

public static Date parseDate(String tp) {
    //2008-03-10 04:32
    String dateFormat = "EEE MMM dd HH:mm:ss zzz yyyy";
    SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
    try {/*w  w w  . ja va 2 s.  co m*/
        return sdf.parse(tp);
    } catch (ParseException e) {
        String dateFormat2 = "yyyy-mm-dd HH:mm";
        SimpleDateFormat sdf2 = new SimpleDateFormat(dateFormat2);
        try {
            return sdf2.parse(tp);
        } catch (ParseException e1) {
            String dateFormat3 = "dd MMM yyyy, HH:mm";
            SimpleDateFormat sdf3 = new SimpleDateFormat(dateFormat3);
            try {
                return sdf3.parse(tp);
            } catch (ParseException e2) {
                e1.printStackTrace();
            }
        }
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

From source file:com.atinternet.tracker.LifeCycle.java

static void newSessionInit(SharedPreferences preferences) {
    try {//  w ww  .  j  a  v a  2 s .c  o  m

        updateFirstSession(preferences);
        // Calcul dsfs
        String firstLaunchDate = preferences.getString(FIRST_SESSION_DATE, "");
        if (!TextUtils.isEmpty(firstLaunchDate)) {
            long timeSinceFirstLaunch = simpleDateFormat.parse(firstLaunchDate).getTime();
            preferences.edit().putInt(DAYS_SINCE_FIRST_SESSION,
                    Tool.getDaysBetweenTimes(System.currentTimeMillis(), timeSinceFirstLaunch)).apply();
        }

        // Calcul dsu
        String firstLaunchDateAfterUpdate = preferences.getString(FIRST_SESSION_DATE_AFTER_UPDATE, "");
        if (!TextUtils.isEmpty(firstLaunchDateAfterUpdate)) {
            long timeSinceFirstLaunchAfterUpdate = simpleDateFormat.parse(firstLaunchDateAfterUpdate).getTime();
            preferences.edit().putInt(DAYS_SINCE_UPDATE,
                    Tool.getDaysBetweenTimes(System.currentTimeMillis(), timeSinceFirstLaunchAfterUpdate))
                    .apply();
        }

        // Calcul dsls
        String lastLaunchDate = preferences.getString(LAST_SESSION_DATE, "");
        if (!TextUtils.isEmpty(lastLaunchDate)) {
            long timeSinceLastUse = simpleDateFormat.parse(lastLaunchDate).getTime();
            preferences.edit().putInt(DAYS_SINCE_LAST_SESSION,
                    Tool.getDaysBetweenTimes(System.currentTimeMillis(), timeSinceLastUse)).apply();
        }
        preferences.edit().putString(LAST_SESSION_DATE, simpleDateFormat.format(new Date())).apply();

        // sc
        preferences.edit().putInt(SESSION_COUNT, preferences.getInt(SESSION_COUNT, 0) + 1).apply();

        // Calcul scsu
        preferences.edit()
                .putInt(SESSION_COUNT_SINCE_UPDATE, preferences.getInt(SESSION_COUNT_SINCE_UPDATE, 0) + 1)
                .apply();

        // Application version changed
        String savedApvr = preferences.getString(VERSION_CODE_KEY, "");
        // Update detected
        if (!versionCode.equals(savedApvr)) {
            preferences.edit().putString(FIRST_SESSION_DATE_AFTER_UPDATE, simpleDateFormat.format(new Date()))
                    .putString(VERSION_CODE_KEY, versionCode).putInt(SESSION_COUNT_SINCE_UPDATE, 1)
                    .putInt(DAYS_SINCE_UPDATE, 0).putBoolean(FIRST_SESSION_AFTER_UPDATE, true).apply();
        }
    } catch (ParseException e) {
        e.printStackTrace();
    }
    sessionId = UUID.randomUUID().toString();
}

From source file:org.openhie.openempi.util.DateUtil.java

/**
 * This method converts a String to a date using the datePattern
 * //from ww  w .  ja  v a 2 s . c  om
 * @param strDate the date to convert (in format MM/dd/yyyy)
 * @return a date object
 * @throws ParseException when String doesn't match the expected format
 */
public static Date convertStringToDate(String strDate) throws ParseException {
    Date aDate = null;

    try {
        if (log.isDebugEnabled()) {
            log.debug("converting date with pattern: " + getDatePattern());
        }

        aDate = convertStringToDate(getDatePattern(), strDate);
    } catch (ParseException pe) {
        log.error("Could not convert '" + strDate + "' to a date, throwing exception");
        pe.printStackTrace();
        throw new ParseException(pe.getMessage(), pe.getErrorOffset());
    }

    return aDate;
}

From source file:de.incoherent.suseconferenceclient.app.SocialWrapper.java

public static ArrayList<SocialItem> getTwitterItems(Context context, String tag, int maximum) {
    String twitterSearch = "http://search.twitter.com/search.json?q=" + tag;
    ArrayList<SocialItem> socialItems = new ArrayList<SocialItem>();

    // TODO Android 2.2 thinks that "Wed, 19 Sep 2012 16:35:43 +0000" is invalid
    // with this formatter
    SimpleDateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z");
    formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
    try {/*from w  ww. j  a  v  a  2  s  .  com*/
        Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.twitter_icon);
        JSONObject result = HTTPWrapper.get(twitterSearch);
        JSONArray items = result.getJSONArray("results");
        int len = items.length();
        if ((len > 0) && (maximum > 0) && (len > maximum))
            len = maximum;

        for (int i = 0; i < len; i++) {
            JSONObject jsonItem = items.getJSONObject(i);
            Bitmap image = HTTPWrapper.getImage(jsonItem.getString("profile_image_url"));
            Date formattedDate = new Date();
            try {
                formattedDate = formatter.parse(jsonItem.getString("created_at"));
            } catch (ParseException e) {
                Log.d("SUSEConferences", "Invalid date string: " + jsonItem.getString("created_at"));
                e.printStackTrace();
            }
            String user = jsonItem.getString("from_user");
            SocialItem newItem = new SocialItem(SocialItem.TWITTER, user, jsonItem.getString("text"),
                    formattedDate,
                    DateUtils
                            .formatDateTime(context, formattedDate.getTime(),
                                    DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_NUMERIC_DATE
                                            | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE),
                    image, icon);
            String link = "http://twitter.com/" + user + "/status/" + jsonItem.getString("id_str");
            newItem.setLink(link);
            socialItems.add(newItem);
        }
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SocketException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return socialItems;
}

From source file:com.swiftcorp.portal.common.util.CalendarUtils.java

public static Date stringToDate(String dateString) {
    DateFormat df = new SimpleDateFormat("dd-MM-yyyy");
    Date today = null;//from  w  ww.  ja  v  a 2  s  . co m
    try {
        today = df.parse(dateString);
        // System.out.println("Today = " + df.format(today));
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return today;
}