List of usage examples for java.text ParseException printStackTrace
public void printStackTrace()
From source file:Main.java
public static long getLocalTime(String strLocalTime) { long millisecond = 0; try {/*from w w w .ja v a 2 s . c om*/ LocalTimeFormatter.setTimeZone(TimeZone.getDefault()); millisecond = LocalTimeFormatter.parse(strLocalTime).getTime(); } catch (ParseException e) { e.printStackTrace(); } return millisecond; }
From source file:Main.java
public static String getDateByAddHour(String datetime, int minute) { String returnTime = null;// ww w .j a v a2 s . com Calendar cal = new GregorianCalendar(); SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date; try { date = ft.parse(datetime); cal.setTime(date); cal.add(GregorianCalendar.MINUTE, minute); returnTime = getFormatDateTime(cal.getTime(), "yyyy-MM-dd HH:mm:ss"); } catch (ParseException e) { e.printStackTrace(); } return returnTime; }
From source file:Main.java
/** * getStringAsDate/*from w w w .jav a2 s. c om*/ * * @param dateString a string in date format * @param format the resulting date format * @return a new date in the specified format */ public static Date getStringAsDate(String dateString, String format, String timezone) { SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.getDefault()); if (timezone == null) { formatter.setTimeZone(TimeZone.getDefault()); } else { formatter.setTimeZone(TimeZone.getTimeZone("UTC")); } Date date = new Date(); try { date = formatter.parse(dateString); } catch (ParseException e) { e.printStackTrace(); } return date; }
From source file:Main.java
public static long getBetweenDiff(String startTime, String endTime, String format) { long diff = 0; SimpleDateFormat ft = new SimpleDateFormat(format); try {//from w w w . j a v a2 s .co m Date startDate = ft.parse(startTime); Date endDate = ft.parse(endTime); diff = startDate.getTime() - endDate.getTime(); diff = diff / 1000; } catch (ParseException e) { e.printStackTrace(); } return diff; }
From source file:Main.java
public static Date stringToDate(String dateString, int dbType) { SimpleDateFormat dateFormat;//from w w w .j a va2s. c o m switch (dbType) { case 1: //SQLite format dateFormat = new SimpleDateFormat("LLL dd, yyyy h:mm:ss aa"); break; case 2: //MySQL format dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); break; default: dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); } Date convDate = new Date(); try { convDate = dateFormat.parse(dateString); } catch (ParseException e) { e.printStackTrace(); } return convDate; }
From source file:Main.java
public static String changeDateFormat(String createDate) { String date = ""; SimpleDateFormat input = new SimpleDateFormat(DATE_SERVER_FORMAT); SimpleDateFormat output = new SimpleDateFormat(DATE_LOCAL_FORMAT); Date formatDate;/* w ww. j av a2 s. c o m*/ try { formatDate = input.parse(createDate); date = output.format(formatDate); } catch (ParseException pe) { pe.printStackTrace(); } return date; }
From source file:Main.java
public static Date string2Date(String s, String style) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(); simpleDateFormat.applyPattern(style); Date date = null;/* www . j ava 2s . c o m*/ if (s == null || s.length() < 6) { return null; } try { date = simpleDateFormat.parse(s); } catch (ParseException e) { e.printStackTrace(); } return date; }
From source file:Main.java
public static String getStringByOffset(String strDate, String format, int calendarField, int offset) { String mDateTime = null;/*from w ww. java2 s.c om*/ try { Calendar c = new GregorianCalendar(); SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format, Locale.CHINA); c.setTime(mSimpleDateFormat.parse(strDate)); c.add(calendarField, offset); mDateTime = mSimpleDateFormat.format(c.getTime()); } catch (ParseException e) { e.printStackTrace(); } return mDateTime; }
From source file:Main.java
/** * convert date string with format yyyy-MM-dd to millisecond * * @param date/*from w ww .j a v a2s . c o m*/ * @return -1 if exception throw */ public static long convertDateStr2Millis(String date) { if (date == null || date.trim().length() == 0) return -1; try { return formatYYYY_MM_DD.parse(date).getTime(); } catch (ParseException e) { e.printStackTrace(); } return -1; }
From source file:Main.java
/** * Convert "yyyy-MM-dd HH:mm:ss" string to date object * //from ww w.j a v a 2 s .c o m * @param dateString * @return */ public static Date ConvertToDate(String dateString) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date convertedDate; try { convertedDate = dateFormat.parse(dateString); } catch (ParseException e) { e.printStackTrace(); return null; } return convertedDate; }