List of usage examples for java.text ParseException printStackTrace
public void printStackTrace()
From source file:com.example.cmput301.model.DatabaseManager.java
/** * Gets list of responses from jsonObject and returns * @param jsonTask , task object in json format. * @return List<Response>// w ww .j a v a 2 s . c om * @throws JSONException */ private static List<Response> toResponses(JSONObject jsonTask) throws JSONException { try { JSONArray jsonArray = jsonTask.getJSONArray("responses"); List<Response> responses = new ArrayList<Response>(); ResponseFactory respFactory = getRespFactory(jsonTask.getString("type")); for (int i = 0; i < jsonArray.length(); i++) { Response resp = respFactory.createResponse(jsonArray.getJSONObject(i).getString("annotation"), jsonArray.getJSONObject(i).getString("content")); resp.setTimestamp(new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy") .parse(jsonArray.getJSONObject(i).getString("timestamp"))); responses.add(resp); } return responses; } catch (ParseException e) { System.err.println("Could not parse date"); e.printStackTrace(); } return null; }
From source file:foam.zizim.android.Util.java
/** * Format date into more readable format. * /*from www. j av a 2 s. c o m*/ * @param date - the date to be formatted. * @return String */ public static String formatDate(String fromFormat, String date, String toFormat) { String formatted = ""; DateFormat formatter = new SimpleDateFormat(fromFormat, Locale.ENGLISH); try { Date dateStr = formatter.parse(date); formatted = formatter.format(dateStr); Date formatDate = formatter.parse(formatted); formatter = new SimpleDateFormat(toFormat); formatted = formatter.format(formatDate); } catch (ParseException e) { e.printStackTrace(); } return formatted; }
From source file:com.otaupdater.utils.Utils.java
public static Date parseDate(String date) { if (date == null) return null; try {//w w w . ja v a 2 s . c o m return OTA_DATE.parse(date); } catch (ParseException e) { e.printStackTrace(); } return null; }
From source file:net.idlesoft.android.apps.github.activities.SingleIssue.java
public static String getTimeSince(final String pTime) { try {/*from www . jav a2 s .com*/ final SimpleDateFormat dateFormat = new SimpleDateFormat(Hubroid.GITHUB_ISSUES_TIME_FORMAT); final Date item_time = dateFormat.parse(pTime); final Date current_time = dateFormat.parse(dateFormat.format(new Date())); final long ms = current_time.getTime() - item_time.getTime(); final long sec = ms / 1000; final long min = sec / 60; final long hour = min / 60; final long day = hour / 24; final long year = day / 365; if (year > 0) { if (year == 1) { return "Updated " + year + " year ago"; } else { return "Updated " + year + " years ago"; } } else if (day > 0) { if (day == 1) { return "Updated " + day + " day ago"; } else { return "Updated " + day + " days ago"; } } else if (hour > 0) { if (hour == 1) { return "Updated " + hour + " hour ago"; } else { return "Updated " + hour + " hours ago"; } } else if (min > 0) { if (min == 1) { return "Updated " + min + " minute ago"; } else { return "Updated " + min + " minutes ago"; } } else { if (sec == 1) { return "Updated " + sec + " second ago"; } else { return "Updated " + sec + " seconds ago"; } } } catch (final ParseException e) { e.printStackTrace(); } return null; }
From source file:ac.elements.parser.SimpleDBConverter.java
public static Object decodeValue(String object) { Object value = null;// w w w. ja v a2 s. co m if (object.indexOf(LONG_TOKEN) == 13) { value = decodeLong(object.substring(0, object.length() - 1)); } else if (object.indexOf(DOUBLE_TOKEN) == 13) { value = decodeSortedDouble(object.substring(0, object.length() - 1)); } else if (object.indexOf(FLOAT_TOKEN) == 7) { value = decodeSortedFloat(object.substring(0, object.length() - 1)); } else if (object.indexOf(INTEGER_TOKEN) == 7) { value = decodeInt(object.substring(0, object.length() - 1)); } else if (object.indexOf(SHORT_TOKEN) == 4) { value = decodeShort(object.substring(0, object.length() - 1)); } // parse date for known tokens else if (object.indexOf('-') == 4 && object.indexOf('-', 5) == 7 && object.indexOf('T') == 10 && object.indexOf(':') == 13 && object.indexOf(':', 14) == 16 && object.indexOf('.') == 19 && object.indexOf('+') == 23) { try { value = decodeDate(object); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { value = (String) object; } return value; }
From source file:com.sccl.attech.common.utils.DateUtils.java
/** * ??//from ww w . j a v a 2 s . c o m */ public static Date getDayAfter(Date date) { Calendar c = Calendar.getInstance(); c.setTime(date); int day = c.get(Calendar.DATE); c.set(Calendar.DATE, day + 1); String dayAfter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(c.getTime()); Date d = null; try { d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dayAfter); } catch (ParseException e) { e.printStackTrace(); } return d; }
From source file:com.sccl.attech.common.utils.DateUtils.java
/** * ??/* w w w . j ava 2s . com*/ * @param startTime * @param endTime * @return * @throws ParseException */ public static Boolean isBetweenTime(Date startTime, Date endTime) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); String current = formatter.format(new Date()); //? Date start; Date end; Date currentTime; try { start = formatter.parse(formatter.format(startTime)); end = formatter.parse(formatter.format(endTime)); currentTime = formatter.parse(current); return ((currentTime.before(end) && currentTime.after(start)) || currentTime.equals(start) || currentTime.equals(end)); } catch (ParseException e) { e.printStackTrace(); } return false; }
From source file:com.fengduo.bee.commons.util.DateViewTools.java
/** * ()?Date?<code>null</code> *//* w ww.j av a2 s.c o m*/ public static Date parseFull(String date) { try { return getFormat(FULL_DATE_FORMAT_PATTERN).parse(date); } catch (ParseException e) { e.printStackTrace(); return null; } }
From source file:com.fengduo.bee.commons.util.DateViewTools.java
/** * ()?Date?<code>null</code> */// w w w . jav a 2s. co m public static Date parseSimple(String date) { try { return getFormat(SIMPLE_DATE_FORMAT_PATTERN).parse(date); } catch (ParseException e) { e.printStackTrace(); return null; } }
From source file:com.alibaba.wasp.plan.parser.druid.DruidParser.java
/** * Parse the SQLExpr value into byte value * /* ww w.ja va 2s . c o m*/ */ public static byte[] convert(Field column, SQLExpr expr) throws UnsupportedException { if (expr instanceof SQLIntegerExpr) {// int, long Number number = ((SQLIntegerExpr) expr).getNumber(); if (column != null) { return convert(column.getType(), number); } else { return convert(null, number); } } else if (expr instanceof SQLCharExpr) {// String String value = ((SQLCharExpr) expr).getText(); if (column != null && column.getType() == DataType.DATETIME) { long timestamp = -1; try { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); timestamp = formatter.parse(value).getTime(); } catch (ParseException e) { //TODO what should i do with the exception? e.printStackTrace(); } return Bytes.toBytes(timestamp); } else { return Bytes.toBytes(value); } } else if (expr instanceof SQLNumberExpr) {// float, double Number number = ((SQLNumberExpr) expr).getNumber(); if (column != null) { return convert(column.getType(), number); } else { return convert(null, number); } } else if (expr instanceof SQLMethodInvokeExpr) { // Function return convert(column.getType(), (SQLMethodInvokeExpr) expr); } return null; }