List of usage examples for java.text SimpleDateFormat parse
public Date parse(String source) throws ParseException
From source file:Main.java
/** * Convert String to java.util.Date//from w w w . jav a 2 s. c om */ public static Date dateFromString(String dateString) { Date convertedDate = null; try { SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy"); convertedDate = formatter.parse(dateString); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return convertedDate; }
From source file:Main.java
public static Date getDateFromString(String date) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); try {//from w w w .j a v a2s . c om return formatter.parse(date); } catch (ParseException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static Date stringToDate(String strTime) throws ParseException { SimpleDateFormat formatter = new SimpleDateFormat(FORMAT_TYPE); Date date = null;/* w w w .j a v a2s. c o m*/ date = formatter.parse(strTime); return date; }
From source file:Main.java
public static Date getDateFromDb(String dateText) { SimpleDateFormat dbDateFormat = new SimpleDateFormat(DATE_FORMAT); try {/* www.j a v a 2 s . com*/ return dbDateFormat.parse(dateText); } catch (ParseException e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static Date getDate(String dateStr, String parsePattern) throws ParseException { Locale locale = Locale.CHINA; SimpleDateFormat dataformat = new SimpleDateFormat(parsePattern, locale); Date date = dataformat.parse(dateStr); return date;/*from w w w . ja v a2 s . co m*/ }
From source file:Main.java
public static Date stringToDate(String strTime, String formatType) throws ParseException { SimpleDateFormat formatter = new SimpleDateFormat(formatType); Date date = null;/*from ww w. j a va 2 s . co m*/ date = formatter.parse(strTime); return date; }
From source file:in.bookmylab.Utils.java
public static Date parseDate(String strDate, String format) throws ParseException { SimpleDateFormat df = new SimpleDateFormat(format); return df.parse(strDate); }
From source file:Main.java
public static Date parseStringToDate(String formatDate, String inputDate) { SimpleDateFormat formatter = new SimpleDateFormat(formatDate); try {//w w w . j a v a 2 s . c o m Date date = formatter.parse(inputDate); return date; } catch (ParseException e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static String formatDate(String dateInput) { try {/*from w w w . jav a2 s . com*/ SimpleDateFormat sdfSource = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Date date = sdfSource.parse(dateInput); SimpleDateFormat sdfDestination = new SimpleDateFormat("dd-MM-yyyy"); dateInput = sdfDestination.format(date); return dateInput.toString(); } catch (ParseException pe) { return dateInput; } }
From source file:Main.java
public static boolean compareDate(String startDate, String endDate) { if (TextUtils.isEmpty(startDate) || TextUtils.isEmpty(endDate)) { return false; }//w w w . ja v a 2 s .co m SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHH"); try { Date dt1 = sdf.parse(startDate); Date dt2 = sdf.parse(endDate); return dt1.after(dt2); } catch (Exception e) { return false; } }