List of usage examples for java.text SimpleDateFormat parse
public Date parse(String source) throws ParseException
From source file:com.fluke.util.Util.java
public static Date getIEODDate(String date) { SimpleDateFormat formatter = new SimpleDateFormat(IEOD_FORMAT); try {/*www. j a v a2s .com*/ return formatter.parse(date); } catch (ParseException ex) { throw new RuntimeException(ex); } }
From source file:Main.java
public static XMLGregorianCalendar toGregorianCaldendar(final String dateString, final SimpleDateFormat formatter) throws ParseException { if (dateString == null || dateString.trim().length() == 0) { return null; }/*from ww w . j a va 2s. co m*/ final Date toReturn = formatter.parse(dateString); return toGregorianCaldendar(toReturn); }
From source file:com.fluke.util.Util.java
public static Date getYahooDate(String date) throws ParseException { SimpleDateFormat formatter = new SimpleDateFormat(YAHOO_FORMAT); try {//from www . ja va 2s . co m return formatter.parse(date); } catch (ParseException ex) { formatter = new SimpleDateFormat(YAHOO_FORMAT_ALTERNATIVE); return formatter.parse(date); } }
From source file:de.csw.linkgenerator.plugin.lucene.IndexFields.java
public static final Date stringToDate(String dateValue) { SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); try {//from w w w . j a va 2 s .c o m return sdf.parse(dateValue); } catch (Exception e) { // silently ignore } return null; }
From source file:Main.java
/** * Coverts the specified date/time value to specific milliseconds. * //from www . j ava 2s.c o m * @param str to convert into specific date/time. * @return converted milliseconds value. */ public static long getDateTimeinMilliSeconds(String str) { long milliseconds = 0; SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //formatter.setTimeZone(TimeZone.getTimeZone("UTC")); Date startdate = null; try { startdate = formatter.parse(str); milliseconds = startdate.getTime(); } catch (ParseException e) { e.printStackTrace(); } return milliseconds; }
From source file:Main.java
public static long DateDifference(String dateStart, String dateStop) { //String dateStart = "01/14/2012 09:29:58"; //String dateStop = "01/15/2012 10:31:48"; //HH converts hour in 24 hours format (0-23), day calculation SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date d1 = null;//from ww w .ja v a 2 s . co m Date d2 = null; long diffDays = -1; try { d1 = format.parse(dateStart); d2 = format.parse(dateStop); //in milliseconds long diff = d1.getTime() - d2.getTime(); long diffSeconds = diff / 1000 % 60; long diffMinutes = diff / (60 * 1000) % 60; long diffHours = diff / (60 * 60 * 1000) % 24; diffDays = diff / (24 * 60 * 60 * 1000); /* Log.v("days",diffDays + " days, "); Log.v("Hours",diffHours + " hours, "); Log.v("Minutes",diffMinutes + " minutes, "); Log.v("Seconds",diffSeconds + " seconds.");*/ } catch (Exception e) { e.printStackTrace(); diffDays = -1; } return diffDays; }
From source file:com.oncecorp.visa3d.bridge.utility.JdbcUtils.java
/** * This method extracts string represented date value into <tt>long</tt> * type value./*w ww . j a va 2s . c o m*/ * @param dateString The string represents the date. * @param dateFormat The format pattern string. The format syntax see the * API document of java.text.SimpleDateFormat. * @return The <tt>long</tt> type value. */ public static long extractDateValue(String dateString, String dateFormat) { SimpleDateFormat format = new SimpleDateFormat(dateFormat); try { Date date = format.parse(dateString); return date.getTime(); } catch (Exception e) { return -1L; } }
From source file:Main.java
/** * Try to parse input with SimpleDateFormat * * @param input input./* ww w .j a v a 2s. c o m*/ * @param format SimpleDateFormat * @param setYear1700 When true the age will be not displayed in brackets * @param locale locale. * @return Date object if successful, otherwise null */ private static Date parseStringWithSimpleDateFormat(String input, String format, boolean setYear1700, Locale locale) { SimpleDateFormat dateFormat = new SimpleDateFormat(format, locale); dateFormat.setTimeZone(TimeZone.getDefault()); try { Date parsedDate = dateFormat.parse(input); /* * Because no year is defined in address book, set year to 1700 * * When year < 1800, the age will be not displayed in brackets */ if (setYear1700) { Calendar cal = Calendar.getInstance(); cal.setTime(parsedDate); cal.set(Calendar.YEAR, 1700); } return parsedDate; } catch (ParseException ignored) { return null; } }
From source file:cn.org.citycloud.srdz.utils.StringUtils.java
public static Date String2Date(String str, String pattern) { SimpleDateFormat sdfDateFormat = new SimpleDateFormat(pattern); try {/*from w w w .j ava 2 s . co m*/ return sdfDateFormat.parse(str); } catch (ParseException e) { // TODO Auto-generated catch block return new Date(); } }
From source file:com.xpn.xwiki.plugin.lucene.IndexFields.java
public static final Date stringToDate(String dateValue) { SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); try {/*from w w w . j a v a2 s .c o m*/ return sdf.parse(dateValue); } catch (Exception e) { // silently ignore } return null; }