List of usage examples for java.text ParseException printStackTrace
public void printStackTrace()
From source file:com.glaf.core.util.DateUtils.java
public static long dateDiff(String beginDateStr, String endDateStr) { long day = 0; java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy-MM-dd"); java.util.Date beginDate;/* w w w.j av a 2s . c o m*/ java.util.Date endDate; try { beginDate = format.parse(beginDateStr); endDate = format.parse(endDateStr); day = (endDate.getTime() - beginDate.getTime()) / (24 * 60 * 60 * 1000); } catch (java.text.ParseException ex) { ex.printStackTrace(); } return day; }
From source file:com.fengduo.bee.commons.util.DateViewTools.java
/** * ??,??/*www . j av a 2s .c o m*/ * * <pre> * ?currentTime > date * ? 2011-11-4 ,isExpirationTime(2011-11-4 ) ture * ? 2011-11-5 ,isExpirationTime(2011-11-4 ) true * * </pre> * * @param date * ? * @return true ?<code>true</code><code>null</code> * <code>true</code>,<code>false</code> */ public static boolean isExpirationTime(Date date) { if (date == null) { return true; } SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); String nows = format.format(new Date()); Date now = null; try { now = format.parse(nows); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (date.compareTo(now) < 0) {// ?? return true; } else {// ?? return false; } }
From source file:com.zigbee.framework.common.util.Utils.java
public static Date getDateStrByDateAndTime(String date, String time) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String str = date;//from w w w .j a v a 2 s .co m if (time != null && !"".equals(time)) { str = str + " " + time + ":00"; } else { return new Date(); } try { return dateFormat.parse(str); } catch (ParseException e) { e.printStackTrace(); return null; } }
From source file:com.turt2live.hurtle.uuid.UUIDServiceProvider.java
/** * Gets the known username history of a UUID. All dates are in UTC. * This returns a map of player names and when they were last seen (the * approximate date they stopped using that name). * * @param uuid the uuid to lookup, cannot be null * * @return a map of names and dates (UTC), or an empty map for invalid input or unknown/non-existent history *//* w ww . j a va 2 s. c o m*/ public static Map<String, Date> getHistory(UUID uuid) { if (uuid == null) return new HashMap<>(); try { URL url = new URL("http://uuid.turt2live.com/history/" + uuid.toString().replaceAll("-", "")); BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); String parsed = ""; String line; while ((line = reader.readLine()) != null) parsed += line; reader.close(); Map<String, Date> map = new HashMap<>(); Object o = JSONValue.parse(parsed); if (o instanceof JSONObject) { JSONObject jsonObject = (JSONObject) o; Object namesObj = jsonObject.get("names"); if (namesObj instanceof JSONArray) { JSONArray names = (JSONArray) namesObj; for (Object name : names) { o = name; if (o instanceof JSONObject) { JSONObject json = (JSONObject) o; Object nameObj = json.get("name"); Object dateObj = json.get("last-seen"); if (nameObj instanceof String && dateObj instanceof String) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); format.setTimeZone(TimeZone.getTimeZone("UTC")); try { Date date = format.parse((String) dateObj); map.put((String) nameObj, date); } catch (ParseException e) { System.out.println("Could not parse " + dateObj + ": " + e.getMessage()); } } } } } } return map; } catch (IOException e) { e.printStackTrace(); } return new HashMap<>(); }
From source file:de.dailab.plistacontest.client.RecommenderItem.java
/** * Parse the ORP json Messages./*from w w w . ja v a2 s . com*/ * * @param _jsonMessageBody * @return the parsed values encapsulated in a map; null if an error has * been detected. */ public static RecommenderItem parseItemUpdate(String _jsonMessageBody) { try { final JSONObject jsonObj = (JSONObject) JSONValue.parse(_jsonMessageBody); String itemID = jsonObj.get("id") + ""; if ("null".equals(itemID)) { itemID = "0"; } String domainID = jsonObj.get("domainid") + ""; String text = jsonObj.get("text") + ""; String flag = jsonObj.get("flag") + ""; boolean recommendable = ("0".equals(flag)); // parse date, now is default String createdAt = jsonObj.get("created_at") + ""; Long created = System.currentTimeMillis(); // maybe the field is called timeStamp instead of created_at if ("null".equals(createdAt)) { created = (Long) jsonObj.get("timestamp"); } else { // parse the date string and derive the long date number try { SimpleDateFormat sdf; sdf = RecommenderItem.sdf.get(); created = sdf.parse(createdAt).getTime(); } catch (ParseException e) { e.printStackTrace(); } } RecommenderItem result = new RecommenderItem(null /* userID */, Long.valueOf(itemID), Long.valueOf(domainID), created); result.setText(text); result.setRecommendable(recommendable); return result; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.fct.api.utils.IdcardUtils.java
/** * 15?????18?//from www . j av a2 s. co m * * @param idCard 15?? * @return 18?? */ public static String conver15CardTo18(String idCard) { String idCard18; if (idCard.length() != CHINA_ID_MIN_LENGTH) { return null; } if (isNum(idCard)) { // ? String birthday = idCard.substring(6, 12); Date birthDate = null; try { birthDate = new SimpleDateFormat("yyMMdd").parse(birthday); } catch (ParseException e) { e.printStackTrace(); } Calendar cal = Calendar.getInstance(); if (birthDate != null) cal.setTime(birthDate); // ?(?,2010) String sYear = String.valueOf(cal.get(Calendar.YEAR)); idCard18 = idCard.substring(0, 6) + sYear + idCard.substring(8); // ? char[] cArr = idCard18.toCharArray(); int[] iCard = converCharToInt(cArr); int iSum17 = getPowerSum(iCard); // ?? String sVal = getCheckCode18(iSum17); if (sVal.length() > 0) { idCard18 += sVal; } else { return null; } } else { return null; } return idCard18; }
From source file:org.dasein.cloud.terremark.Terremark.java
public static Date parseIsoDate(String isoDateString) { java.text.DateFormat df = new SimpleDateFormat(ISO8601_PATTERN); df.setTimeZone(TimeZone.getTimeZone("UTC")); Date result = null;/*from w ww . ja v a2s . com*/ try { result = df.parse(isoDateString); } catch (ParseException e) { df = new SimpleDateFormat(ISO8601_NO_MS_PATTERN); df.setTimeZone(TimeZone.getTimeZone("UTC")); result = null; try { result = df.parse(isoDateString); } catch (ParseException e2) { e2.printStackTrace(); } } return result; }
From source file:com.tenmiles.helpstack.gears.HSHappyfoxGear.java
protected static Date parseTime(String dateString) { Date givenTimeDate = null;/* w w w .j a v a 2 s.co m*/ try { givenTimeDate = parseUTCString(dateString, "yyyy-MM-dd HH:mm:ss"); } catch (ParseException e) { try { givenTimeDate = parseUTCString(dateString, "yyyy-MM-dd"); } catch (ParseException e1) { try { givenTimeDate = parseUTCString(dateString, "yyyy-MM-dd HH:mm:ss.SSSSZ"); } catch (ParseException e2) { e2.printStackTrace(); } } } return givenTimeDate; }
From source file:com.eeesys.frame.utils.IdcardTool.java
/** * ?15????//from ww w . j ava 2 s . c om * * @param idCard ? * @return ?? */ public static boolean validateIdCard15(String idCard) { if (idCard.length() != CHINA_ID_MIN_LENGTH) { return false; } if (isNum(idCard)) { String proCode = idCard.substring(0, 2); if (cityCodes.get(proCode) == null) { return false; } String birthCode = idCard.substring(6, 12); Date birthDate = null; try { birthDate = new SimpleDateFormat("yy").parse(birthCode.substring(0, 2)); } catch (ParseException e) { e.printStackTrace(); } Calendar cal = Calendar.getInstance(); if (birthDate != null) cal.setTime(birthDate); if (!valiDate(cal.get(Calendar.YEAR), Integer.valueOf(birthCode.substring(2, 4)), Integer.valueOf(birthCode.substring(4, 6)))) { return false; } } else { return false; } return true; }
From source file:com.domain.java.util.IDCardUtils.java
/** * ?15????//from www .java2 s. c o m * @param idCard ? * @return ?? */ public static boolean validateIdCard15(String idCard) { if (idCard.length() != CHINA_ID_MIN_LENGTH) { return false; } if (isNum(idCard)) { String proCode = idCard.substring(0, 2); if (cityCodes.get(proCode) == null) { return false; } String birthCode = idCard.substring(6, 12); Date birthDate = null; try { birthDate = new SimpleDateFormat("yy").parse(birthCode.substring(0, 2)); } catch (ParseException e) { e.printStackTrace(); } Calendar cal = Calendar.getInstance(); if (birthDate != null) cal.setTime(birthDate); if (!valiDate(cal.get(Calendar.YEAR), Integer.valueOf(birthCode.substring(2, 4)), Integer.valueOf(birthCode.substring(4, 6)))) { return false; } } else { return false; } return true; }