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:Main.java

public static String formatExpirationDate(String text) {

    try {//w  w w . ja  v  a2  s . com
        switch (text.length()) {
        case 1:
            int digit = Integer.parseInt(text);

            if (digit < 2) {
                return text;
            } else {
                return "0" + text + "/";
            }
        case 2:
            int month = Integer.parseInt(text);
            if (month > 12 || month < 1) {
                // Invalid digit
                return text.substring(0, 1);
            } else {
                return text + "/";
            }
        case 3:
            if (text.substring(2, 3).equalsIgnoreCase("/")) {
                return text;
            } else {
                text = text.substring(0, 2) + "/" + text.substring(2, 3);
            }
        case 4:
            Calendar now = getCurrentExpDate();
            String year = String.valueOf(now.get(Calendar.YEAR));
            int yearDigit = Integer.parseInt(text.substring(3, 4));
            int currentYearDigit = Integer.parseInt(year.substring(2, 3));
            if (yearDigit < currentYearDigit) {
                // Less than current year invalid
                return text.substring(0, 3);
            } else {
                return text;
            }
        case 5:
            Calendar now2 = getCurrentExpDate();
            String currentYearStr2 = String.valueOf(now2.get(Calendar.YEAR));
            String yearStr = text.substring(0, 3) + currentYearStr2.substring(0, 2) + text.substring(3, 5);
            Date expiry = simpleDateFormat.parse(yearStr);
            if (expiry.before(now2.getTime())) {
                // Invalid exp date
                return text.substring(0, 4);
            } else {
                return text;
            }
        default:
            if (text.length() > 5) {
                return text.substring(0, 5);
            } else {
                return text;
            }
        }

    } catch (ParseException e) {
        e.printStackTrace();
    }
    // If an exception is thrown we clear out the text
    return "";
}

From source file:com.common.server.AppLicenceUtil.java

public static void logonVertify() throws Exception {
    Map map = getLicence();//from  w w  w.  j  a va2s .c  o  m
    String expire = (String) map.get("expireDate");
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

    if (expire == null) {
        return;
    }
    Date expireDate = null;
    try {
        expireDate = format.parse(expire);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    Date currentDate = new Date();
    if (currentDate.compareTo(expireDate) >= 0) {
        log.info(":expire=" + expire + "  currentDate=" + format.format(currentDate));

    }
    log.info(":expire=" + expire + "  currentDate=" + format.format(currentDate));
}

From source file:com.oa.product.action.MyDateUtils.java

/**
 * ???"yyyy-MM-dd HH:mm:ss"/*from w  w w .j  a  v a2s.  c om*/
 * 
 * @param date
 * @return
 */
public static Date getDateStart(Date date) {
    if (date == null) {
        return null;
    }
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    try {
        date = sdf.parse(formatDate(date, "yyyy-MM-dd") + " 00:00:00");
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return date;
}

From source file:com.oa.product.action.MyDateUtils.java

/**
 * ????"yyyy-MM-dd HH:mm:ss"/*from  w  w w . j a va 2  s  . co  m*/
 * 
 * @param date
 * @return
 */
public static Date getDateEnd(Date date) {
    if (date == null) {
        return null;
    }
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    try {
        date = sdf.parse(formatDate(date, "yyyy-MM-dd") + " 23:59:59");
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return date;
}

From source file:driimerfinance.helpers.FinanceHelper.java

/**
 * unformats a formatted number to be a double again
 * /*from   w  w  w .  j av a 2s.  co m*/
 * @param string number to convert
 * @return an unformatted number to be used for db interactions
 */
public static double unformatAmount(String formattedNumber) {
    NumberFormat numberFormatter = NumberFormat.getCurrencyInstance();
    Number number = null;
    try {
        number = numberFormatter.parse(formattedNumber);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    double unformattedNumber = number.doubleValue();
    return unformattedNumber;
}

From source file:com.b5m.user.frame.util.DateUtils.java

public static Date String2Date(String dateStr, String DateFormat) {
    SimpleDateFormat sdf = new SimpleDateFormat(DateFormat);
    try {/*from   w  w  w. j  ava2 s. co  m*/
        return sdf.parse(dateStr);
    } catch (ParseException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static String formatExpirationDate(String text) {

    try {//from w  w  w.ja  v a 2s  . c  o m
        switch (text.length()) {
        case 1:
            int digit = Integer.parseInt(text);

            if (digit < 2) {
                return text;
            } else {
                return "0" + text + "/";
            }
        case 2:
            int month = Integer.parseInt(text);
            if (month > 12 || month < 1) {
                // Invalid digit
                return text.substring(0, 1);
            } else {
                return text + "/";
            }
        case 3:
            if (text.substring(2, 3).equalsIgnoreCase("/")) {
                return text;
            } else {
                text = text.substring(0, 2) + "/" + text.substring(2, 3);
            }
        case 4:
            int yearDigit = Integer.parseInt(text.substring(3, 4));
            String year = String.valueOf(Calendar.getInstance().get(Calendar.YEAR));
            int currentYearDigit = Integer.parseInt(year.substring(2, 3));
            if (yearDigit < currentYearDigit) {
                // Less than current year invalid
                return text.substring(0, 3);
            } else {
                return text;
            }
        case 5:
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/yy");
            simpleDateFormat.setLenient(false);
            Date expiry = simpleDateFormat.parse(text);
            if (expiry.before(new Date())) {
                // Invalid exp date
                return text.substring(0, 4);
            } else {
                return text;
            }
        default:
            if (text.length() > 5) {
                return text.substring(0, 5);
            } else {
                return text;
            }
        }

    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // If an exception is thrown we clear out the text
    return "";
}

From source file:Main.java

public static String formatExpirationDate(String text) {
    try {//w  ww  . j  av a  2 s  .com
        switch (text.length()) {
        case 1:
            int digit = Integer.parseInt(text);

            if (digit < 2) {
                return text;
            } else {
                return "0" + text + "/";
            }
        case 2:
            int month = Integer.parseInt(text);
            if (month > 12 || month < 1) {
                // Invalid digit
                return text.substring(0, 1);
            } else {
                return text + "/";
            }
        case 3:
            if (text.substring(2, 3).equalsIgnoreCase("/")) {
                return text;
            } else {
                text = text.substring(0, 2) + "/" + text.substring(2, 3);
            }
        case 4:
            Calendar now = getCurrentExpDate();
            String currentYearStr = String.valueOf(now.get(Calendar.YEAR));

            int yearDigit = Integer.parseInt(text.substring(3, 4));
            int currentYearDigit = Integer.parseInt(currentYearStr.substring(2, 3));
            if (yearDigit < currentYearDigit) {
                // Less than current year invalid
                return text.substring(0, 3);
            } else {
                return text;
            }
        case 5:
            // always make the year in the current century
            Calendar now2 = getCurrentExpDate();
            String currentYearStr2 = String.valueOf(now2.get(Calendar.YEAR));
            String yearStr = text.substring(0, 3) + currentYearStr2.substring(0, 2) + text.substring(3, 5);
            Date expiry = simpleDateFormat.parse(yearStr);
            if (expiry.before(now2.getTime())) {
                // Invalid exp date
                return text.substring(0, 4);
            } else {
                return text;
            }
        default:
            if (text.length() > 5) {
                return text.substring(0, 5);
            } else {
                return text;
            }
        }

    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // If an exception is thrown we clear out the text
    return "";
}

From source file:com.gst.integrationtests.common.Utils.java

public static String convertDateToURLFormat(final String dateToBeConvert) {
    final SimpleDateFormat oldFormat = new SimpleDateFormat("dd MMMMMM yyyy", Locale.US);
    final SimpleDateFormat newFormat = new SimpleDateFormat("yyyy-MM-dd");
    String reformattedStr = "";
    try {/* w w  w.  jav a 2s.co  m*/
        reformattedStr = newFormat.format(oldFormat.parse(dateToBeConvert));
    } catch (final ParseException e) {
        e.printStackTrace();
    }
    return reformattedStr;
}

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

public static ArrayList<SocialItem> getGooglePlusItems(Context context, String tag, int maximum) {
    String twitterSearch = "https://www.googleapis.com/plus/v1/activities?orderBy=recent&query=" + tag + "&key="
            + Config.PLUS_KEY;/*  www.ja  v  a  2  s . c o m*/
    Log.d("SUSEConferences", "Google search: " + twitterSearch);
    ArrayList<SocialItem> socialItems = new ArrayList<SocialItem>();
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'");
    formatter.setTimeZone(TimeZone.getTimeZone("UTC"));

    Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.google_icon);

    try {
        JSONObject result = HTTPWrapper.get(twitterSearch);
        JSONArray items = result.getJSONArray("items");
        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);
            JSONObject actorItem = jsonItem.getJSONObject("actor");
            JSONObject imageItem = actorItem.getJSONObject("image");
            JSONObject objectItem = jsonItem.getJSONObject("object");
            Bitmap image = HTTPWrapper.getImage(imageItem.getString("url"));
            String content = Html.fromHtml(objectItem.getString("content")).toString();
            Date formattedDate = new Date();
            try {
                formattedDate = formatter.parse(jsonItem.getString("published"));
            } catch (ParseException e) {
                e.printStackTrace();
            }

            SocialItem newItem = new SocialItem(SocialItem.GOOGLE, actorItem.getString("displayName"), content,
                    formattedDate,
                    DateUtils
                            .formatDateTime(context, formattedDate.getTime(),
                                    DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_NUMERIC_DATE
                                            | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE),
                    image, icon);
            newItem.setLink(jsonItem.getString("url"));
            socialItems.add(newItem);
        }
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (SocketException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return socialItems;
}