List of usage examples for java.text SimpleDateFormat parse
public Date parse(String source) throws ParseException
From source file:Main.java
/** * String->imestamp/*from w ww .j a v a 2s . co 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); }
From source file:Main.java
/** * Converts an XML xs:datetime string to a Calendar object. We do not mess * around with formatting issues. It either works, or it doesn't. * * @param xsDateTime the xs:datetime formatted string * * @return the Calendar object// ww w.j a v a2 s . co m * * @throws ParseException if a parsing error occurs */ public static Calendar xsDateTimeToCalendar(final String xsDateTime) throws ParseException { Calendar newCal = null; if (xsDateTime != null) { // -06:00 goes to -0600 final String fixedTime = xsDateTime.replaceAll("([-+]??\\d{2}):??(\\d{2})$", "$1$2"); final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); final Date date = dateFormat.parse(fixedTime); newCal = GregorianCalendar.getInstance(); newCal.setTime(date); } return newCal; }
From source file:Main.java
public static String changeStringToDate3(String str) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); java.util.Date date6 = null;/*from www .j av a 2 s . c o m*/ try { date6 = sdf.parse(str); java.sql.Date date7 = new java.sql.Date(date6.getTime()); Timestamp stamp9 = new Timestamp(date7.getTime()); return stamp9.toString(); } catch (ParseException e) { e.printStackTrace(); return ""; } }
From source file:Main.java
public static String getStringByDateFormat(String strDate, String format) { String mDateTime = null;//from w ww . j a v a 2 s .c o m try { Calendar c = new GregorianCalendar(); SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat("MMM dd,yyyy kk:mm:ss aa", Locale.ENGLISH); c.setTime(mSimpleDateFormat.parse(strDate)); SimpleDateFormat mSimpleDateFormat2 = new SimpleDateFormat(format); mDateTime = mSimpleDateFormat2.format(c.getTime()); } catch (Exception e) { e.printStackTrace(); } return mDateTime; }
From source file:Main.java
public static String getFormattedDate(String date) { SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss Z"); Date newDate = null;/*from w ww . ja v a2 s.c om*/ try { newDate = format.parse(date); } catch (ParseException e) { e.printStackTrace(); } format = new SimpleDateFormat("MMM dd, yyyy hh:mm a"); return format.format(newDate); }
From source file:Main.java
public static Date getDateWithTPattern(Context context, String strDate) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd'T'HH:mm:ss"); // sdf.setTimeZone(TimeZone.getTimeZone("GMT")); Date date = sdf.parse(strDate); return date;/*from w w w.j a va 2 s.c o m*/ }
From source file:Main.java
public static Date stringToDate(String mFirstDate, SimpleDateFormat yearformat) { Date parse = null;//from w w w . j a v a 2s.c om try { if (mFirstDate != null) { parse = yearformat.parse(mFirstDate); } } catch (ParseException e) { e.printStackTrace(); } return parse; }
From source file:common.ClassUtils.java
public static void copyProperty(Object dest, String name, Object value) { try {/*from w w w.j a v a 2 s. c o m*/ // ?Date ConvertUtils.register(new Converter() { public Object convert(Class type, Object value) { //198a if (value == null) { return null; } String s = (String) value; if (s.trim().equals("")) { return null; } SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); try { return sdf.parse(s); } catch (ParseException e) { throw new RuntimeException(e); } } }, Date.class); BeanUtils.copyProperty(dest, name, value); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:Main.java
public static Date getDateForString(String dateString) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); Date date = null;//from w ww. j av a2 s. co m try { date = dateFormat.parse(dateString); } catch (ParseException e) { e.printStackTrace(); } return date; }
From source file:Main.java
public static long dateToMilli(String dateString) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); sdf.setTimeZone(TimeZone.getDefault()); try {//w w w.ja v a 2 s. co m return sdf.parse(dateString).getTime(); } catch (ParseException e) { e.printStackTrace(); } return 0; }