List of usage examples for java.text ParseException printStackTrace
public void printStackTrace()
From source file:Main.java
public static String convertUtc2LocalPro(String utcTime) { if (TextUtils.isEmpty(utcTime)) { return ""; }//from www . jav a 2s . co m // 2014-10-24T02:58:05.932Z SimpleDateFormat utcFormatter, localFormatter; utcFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ENGLISH); Date date; Calendar cal = Calendar.getInstance(); try { date = utcFormatter.parse(utcTime); cal.setTime(date); } catch (ParseException e) { e.printStackTrace(); } cal.add(Calendar.HOUR_OF_DAY, +8); date = cal.getTime(); localFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); return localFormatter.format(date); }
From source file:Main.java
/** * User friendly date format//from w w w . j av a 2 s . c om * * @param date * */ public static String getDateUserFormat(String date) { String formatedDate = ""; if (date != null) { if (date.length() != 0) { SimpleDateFormat userFormat = new SimpleDateFormat("d MMM yyyy"); SimpleDateFormat sqlFormat = new SimpleDateFormat("yyyy-MM-dd"); try { formatedDate = userFormat.format(sqlFormat.parse(date)); } catch (ParseException e) { e.printStackTrace(); } } } return formatedDate; }
From source file:Main.java
private static Boolean currentGreaterThenOld(String currentDate, String oldDate) { if (currentDate.isEmpty() || oldDate.isEmpty()) return false; try {/*from ww w . j a v a 2s. co m*/ SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault()); Date current = formatter.parse(currentDate); Date old = formatter.parse(oldDate); if (old.compareTo(current) < 0) { Log.d(TAG, "compareDate current Date : " + current.toString() + " is greater then Old Date : " + old.toString()); return true; } } catch (ParseException e1) { e1.printStackTrace(); } return false; }
From source file:Main.java
public static Date strToDate(String dateStr, String format) { Date date = null;//from w w w . j a va 2s . c om if (dateStr != null && (!dateStr.equals(""))) { DateFormat df = new SimpleDateFormat(format); try { date = df.parse(dateStr); } catch (ParseException e) { e.printStackTrace(); } } return date; }
From source file:Main.java
public static Date strToDate(String dateStr) { Date date = null;//from w w w .ja v a2 s .c o m if (dateStr != null && (!dateStr.equals(""))) { DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { date = df.parse(dateStr); } catch (ParseException e) { e.printStackTrace(); } } return date; }
From source file:Main.java
public static boolean timeCompare(String beforeTime, String endTime, String format) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format); try {/*w w w .ja va 2 s . com*/ Date beforeDate = simpleDateFormat.parse(beforeTime); long beforeTimeLong = beforeDate.getTime(); Date endDate = simpleDateFormat.parse(endTime); long endTimeLong = endDate.getTime(); return beforeTimeLong > endTimeLong; } catch (ParseException e) { e.printStackTrace(); } return false; }
From source file:Main.java
public static boolean judgeTime2Time(String time1, String time2) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); try {//from w w w. ja v a 2 s . c o m Date date1 = sdf.parse(time1); Date date2 = sdf.parse(time2); long l1 = date1.getTime() / 1000; long l2 = date2.getTime() / 1000; if (l2 - l1 > 0) { return true; } else { return false; } } catch (ParseException e) { e.printStackTrace(); } return false; }
From source file:Main.java
public static String convertUtc2Local(String utcTime) { String time = ""; if (utcTime != null) { // 2014-10-24T02:58:05.932Z SimpleDateFormat utcFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.CHINA); utcFormatter.setTimeZone(TimeZone.getTimeZone("UTC")); Date gpsUTCDate = null;//w w w . ja v a 2 s.c o m try { gpsUTCDate = utcFormatter.parse(utcTime); } catch (ParseException e) { e.printStackTrace(); } SimpleDateFormat localFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); localFormatter.setTimeZone(TimeZone.getDefault()); assert gpsUTCDate != null; time = localFormatter.format(gpsUTCDate.getTime()); } return time; }
From source file:Main.java
public static double getDoubleFromCurrencyString(String formattedString) { NumberFormat nf = NumberFormat.getCurrencyInstance(); // really lazy this shouldn't blindly check for whether it is a currency or not.. try {/*from w w w . j a va 2 s . c om*/ return nf.parse(formattedString).doubleValue(); } catch (ParseException e) { e.printStackTrace(); } return getDoubleFrom(formattedString); }
From source file:Main.java
/** * String->imestamp/*w w w . j a v a 2 s . c o m*/ * * @param str * @param format * @return */ public static Timestamp strToTimestamp(String str, String format) { // "yyyy-MM-dd HH:mm:ss" SimpleDateFormat df1 = new SimpleDateFormat(format); Date date1 = new Date(); try { date1 = df1.parse(str); } catch (ParseException e) { e.printStackTrace(); } String time = df1.format(date1); // Timestamp ts = Timestamp.valueOf(time); return Timestamp.valueOf(time); }