List of usage examples for java.text SimpleDateFormat parse
public Date parse(String source) throws ParseException
From source file:Main.java
public static String convertDate(String fromDate) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); Date convertedDate = null;/* w ww . j a va2 s. c o m*/ try { convertedDate = sdf.parse(fromDate); SimpleDateFormat formatter = new SimpleDateFormat("MMM dd, yyyy"); String convertedDateString = formatter.format(convertedDate); return convertedDateString; } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:Main.java
public static String getFormattedTime(String time) { SimpleDateFormat sdfDate = new SimpleDateFormat("dd-MM-yyyy HH:mm", Locale.ENGLISH); String strDate = null;//from w w w . j av a 2 s . c o m try { strDate = String.valueOf(sdfDate.parse(time)); } catch (ParseException e) { e.printStackTrace(); strDate = ""; } return strDate; }
From source file:Main.java
/** * Convert "yyyy-MM-dd HH:mm:ss" string to date object * /*from ww w .j ava 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; }
From source file:Main.java
public static Date parseXmlDate(String xmlDateStr) throws Exception { if (xmlDateStr == null || xmlDateStr.trim().length() < 1) { return null; }//from w w w. ja v a 2 s. c o m SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'.'SSSZ"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); return sdf.parse(xmlDateStr); }
From source file:Main.java
public static Date getDateFromDateStringWithoutss(String dateStr, String template) { SimpleDateFormat formatter; Date date = null;/*from www.j a va 2 s . com*/ formatter = new SimpleDateFormat(template, java.util.Locale.CHINA); try { date = (Date) formatter.parse(dateStr); } catch (ParseException e) { e.printStackTrace(); } return date; }
From source file:Main.java
public static String getTimeStamp(String time) { SimpleDateFormat sdr = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.CHINA); Date date;/*from w w w .j a va 2 s. co m*/ String times = null; try { date = sdr.parse(time); long l = date.getTime(); String stf = String.valueOf(l); times = stf.substring(0, 10); } catch (ParseException e) { e.printStackTrace(); } return times; }
From source file:Main.java
public static String formatDate(String strDate) { try {/*from w w w .j a v a 2 s. c o m*/ // create SimpleDateFormat object with source string date format SimpleDateFormat sdfSource = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // parse the string into Date object Date date = sdfSource.parse(strDate); Date now = new Date(); SimpleDateFormat sdfDestination; if (date.getYear() == now.getYear()) sdfDestination = new SimpleDateFormat("dd MMM"); else sdfDestination = new SimpleDateFormat("dd/MM/yyyy"); return "Added on: " + sdfDestination.format(date); } catch (ParseException pe) { return ""; } }
From source file:Main.java
/** * Parsing the TimeZone of time in milliseconds. * * @param gmtTime GRM Time, Format such as: {@value #FORMAT_HTTP_DATA}. * @return The number of milliseconds from 1970.1.1. * @throws ParseException if an error occurs during parsing. */// w w w . j a v a2 s.c o m public static long parseGMTToMillis(String gmtTime) throws ParseException { SimpleDateFormat formatter = new SimpleDateFormat(FORMAT_HTTP_DATA, Locale.US); formatter.setTimeZone(GMT_TIME_ZONE); Date date = formatter.parse(gmtTime); return date.getTime(); }
From source file:com.intuit.tank.vm.common.util.ReportUtil.java
public static Date parseTimestamp(String dateString) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); return sdf.parse(dateString); }
From source file:com.microsoft.exchange.DateHelper.java
/** * //from w w w. j a v a 2 s. c om * @param value * @return */ public static Date makeDate(String value) { SimpleDateFormat df = new SimpleDateFormat(DATE_FORMAT); try { Date date = df.parse(value); return DateUtils.truncate(date, java.util.Calendar.DATE); } catch (ParseException e) { throw new IllegalArgumentException(value + " does not match expected format " + DATE_FORMAT, e); } }