List of usage examples for java.text SimpleDateFormat parse
public Date parse(String source) throws ParseException
From source file:Main.java
public static boolean checkDate(String str, String format) { SimpleDateFormat formatter = new SimpleDateFormat(format); try {/* w ww . j a v a 2 s .co m*/ formatter.parse(str); return true; } catch (Exception e) { return false; } }
From source file:Main.java
public static Date parseDateForTimeFilter(String date) { try {/*from ww w . j a v a2 s . co m*/ SimpleDateFormat myDateFormat = new SimpleDateFormat("hh:mm a"); Date tempDate = myDateFormat.parse(date); return tempDate; } catch (ParseException e) { return new Date(0); } }
From source file:Main.java
public static long getMillisTimeStr(String time, String pattern) { SimpleDateFormat sdf = new SimpleDateFormat(pattern); try {/*from www . ja va 2 s . c o m*/ long millis = sdf.parse(time).getTime(); return millis; } catch (ParseException e) { e.printStackTrace(); } return -1; }
From source file:Main.java
public static Calendar dateShortBrToCalendar(String data) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("MMM/yyyy", Locale.getDefault()); Date date = sdf.parse(data); Calendar calendar = Calendar.getInstance(); calendar.setTime(date);/*from w w w .j av a 2s . co m*/ return calendar; }
From source file:Main.java
public static Date getDateFromString(String timeStr, String format) { SimpleDateFormat dateFormat = new SimpleDateFormat(format); try {// ww w. ja v a2 s . co m return dateFormat.parse(timeStr); } catch (ParseException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static boolean isBeforeTime(String date1, String date2) { try {/* ww w . j av a 2 s . c o m*/ SimpleDateFormat dfDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return dfDateFormat.parse(date1).before(dfDateFormat.parse(date2)); } catch (ParseException e) { e.printStackTrace(); } return false; }
From source file:Main.java
public static String dateStringFormate(String yyyyMMddhhmmss) { try {//from w ww. j a va2 s. com SimpleDateFormat format1 = new SimpleDateFormat("yyyyMMddHHmmss"); Date date = format1.parse(yyyyMMddhhmmss.replace(" ", "")); SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return format2.format(date); } catch (Exception e) { e.printStackTrace(); return yyyyMMddhhmmss; } }
From source file:Main.java
public static Date getDateFromString(String date, String pattern) { Date dateObj = new Date(); SimpleDateFormat sdf = new SimpleDateFormat(pattern); try {//from w ww . j a va 2 s . com dateObj = sdf.parse(date); } catch (ParseException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return dateObj; }
From source file:Main.java
public static Date getDateFromString(String time, String formatString) { Date date = new Date(System.currentTimeMillis()); SimpleDateFormat format = new SimpleDateFormat(formatString); try {/*from w w w . ja v a 2 s .c om*/ date = format.parse(time); } catch (ParseException e) { e.printStackTrace(); } return date; }
From source file:Main.java
public static Date stringToDate(String dateStr, String dateFormat) { SimpleDateFormat formatter = new SimpleDateFormat(dateFormat); try {// w w w. j ava2s .c o m return formatter.parse(dateStr); } catch (ParseException e) { return null; } }