List of usage examples for java.text SimpleDateFormat parse
public Date parse(String source) throws ParseException
From source file:Main.java
public static Date getDateFromString(String date) { SimpleDateFormat sf = new SimpleDateFormat("EEE MMM dd HH:mm:ss ZZZZZ yyyy"); sf.setLenient(true);/* w ww. j a v a 2 s . c om*/ Date ret = new Date(); try { ret = sf.parse(date); } catch (ParseException e) { e.printStackTrace(); } return ret; }
From source file:Main.java
/** * Parse a time character array as defined in PKCS#11 and return is as a * Date object.//from www . ja va 2s . c o m * * @param timeChars A time encoded as character array as specified in PKCS#11. * @return A Date object set to the time indicated in the given char-array. * null, if the given char array is null or the format is wrong. * @preconditions * @postconditions */ public static Date parseTime(char[] timeChars) { Date time = null; if ((timeChars != null) && timeChars.length > 2) { String timeString = new String(timeChars, 0, timeChars.length - 2); try { SimpleDateFormat utc = new SimpleDateFormat("yyyyMMddhhmmss"); utc.setTimeZone(TimeZone.getTimeZone("UTC")); time = utc.parse(timeString); // time = new SimpleDateFormat("yyyyMMddhhmmss").parse(timeString); } catch (ParseException ex) { /* nothing else to be done */ } } return time; }
From source file:Main.java
public static Date getExifDate(File imgFile) throws IOException { ExifInterface imgFileExif = new ExifInterface(imgFile.getCanonicalPath()); if (imgFileExif.getAttribute(ExifInterface.TAG_DATETIME) != null) { String imgDateTime = imgFileExif.getAttribute(ExifInterface.TAG_DATETIME); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss", Locale.US); try {//from www . j a v a 2 s . c om return simpleDateFormat.parse(imgDateTime); } catch (ParseException e) { e.printStackTrace(); } } return null; }
From source file:Main.java
public static Date ConvertFromWebService(final String strDate) { final String[] formats = new String[] { "yyyy-MM-dd'T'HH:mm:ss.SSS", "yyyy-MM-dd'T'HH:mm:ss.SSSXXX", "yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd'T'HH:mm", "yyyy-MM-dd" }; for (final String frm : formats) { try {/*ww w . j ava2 s.c o m*/ final SimpleDateFormat format = new SimpleDateFormat(frm, Locale.US); format.setTimeZone(TimeZone.getTimeZone("UTC")); return format.parse(strDate); } catch (final Exception ex) { Log.e("IGWHelper", "Failed to convert Web Service Date.", ex); } } return null; }
From source file:Main.java
/** *Converts a dateTimeString and makes a Calendar object * @param dateTimeString in format 2012-10-15T08:17:00 * @return Calendar object//from ww w . j a v a2 s . co m * */ public static Calendar parseCalendarString(String dateTimeString) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); Date date = null; try { date = dateFormat.parse(dateTimeString); } catch (ParseException e) { e.printStackTrace(); } Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("Europe/Stockholm")); cal.setTime(date); return cal; }
From source file:Main.java
public static String dateString2dateString(String date, String originFormater, String destFormater) { if (date == null || "".equals(date)) return ""; SimpleDateFormat formater = new SimpleDateFormat(); try {/*from www .j ava2s .co m*/ formater.applyPattern(originFormater); Date time = formater.parse(date); return date2String(destFormater, time); } catch (ParseException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
/** * Parse the date from server to String for local database * * @param date_received date received from server * @return Date for storing in local database */// w w w. ja v a 2s . co m public static Date parseDateFromString(String date_received) { //2014-06-28 14:56:59 SimpleDateFormat dateFormat_received = new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss", Locale.getDefault()); Date date = null; try { date = dateFormat_received.parse(date_received); } catch (ParseException e) { e.printStackTrace(); } return date; }
From source file:Main.java
public static Date dateFromDateTimeString(String dateTimeString) throws ParseException { String dateTimeStringPattern; Date date;/*w w w. j a va2 s .c o m*/ SimpleDateFormat dateFormatter; dateTimeStringPattern = "HH:mm:ss.SSS MM-dd-yyy"; dateFormatter = new SimpleDateFormat(dateTimeStringPattern); date = dateFormatter.parse(dateTimeString); return date; }
From source file:org.devdom.commons.util.Utils.java
/** * //from w w w . j a v a2 s .c o m * Mtodo utilizado para convertir un objeto Strign en un objeto fecha * indicando el formato en el segundo parmetro. * * @param date * @param format * @return * @throws ParseException */ public static Date convertStringToDate(String date, String format) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat(format); return sdf.parse(date); }
From source file:com.microsoft.exchange.DateHelper.java
/** * /*from ww w . j a v a 2s.co m*/ * @param value * @return */ public static Date makeDateTime(String value) { SimpleDateFormat df = new SimpleDateFormat(DATE_TIME_FORMAT); try { Date date = df.parse(value); return DateUtils.truncate(date, java.util.Calendar.MINUTE); } catch (ParseException e) { throw new IllegalArgumentException(value + " does not match expected format " + DATE_FORMAT, e); } }