List of usage examples for java.text SimpleDateFormat parse
public Date parse(String source) throws ParseException
From source file:gov.nih.nci.caintegrator.common.DateUtil.java
/** * @param dateString string represent of Date * @return Date object/*from w w w . j a v a 2 s. c o m*/ * @throws ParseException parsing exception */ public static Date createDate(String dateString) throws ParseException { if (StringUtils.isBlank(dateString)) { return null; } SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy", Locale.getDefault()); return formatter.parse(formatDate(dateString)); }
From source file:com.itd.dbmrgdao.TestTime3_backup.java
protected static String CompareTime(String a, String b, String operator) throws ParseException { if (a == null) { return b; }//from ww w. ja v a 2s. co m SimpleDateFormat parser1 = new SimpleDateFormat("HHmm"); Date x = parser1.parse(a); Date y = parser1.parse(b); try { // The Magic happens here i only get the Time out of the Date Object SimpleDateFormat parser2 = new SimpleDateFormat("HH:mm"); x = parser2.parse(parser2.format(x)); y = parser2.parse(parser2.format(y)); } catch (ParseException ex) { System.err.println(ex); } switch (operator) { case "01": return ((x.compareTo(y) <= 0) ? a : b); case "04": return ((x.compareTo(y) >= 0) ? a : b); default: throw new IllegalArgumentException("Operator " + operator + " not fould in control!"); } }
From source file:Main.java
public static String getDateForMouth(String dateString) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); SimpleDateFormat simpledateformat = new SimpleDateFormat("MM-dd"); String s = ""; Date newDate = null;//from w w w .ja v a 2 s.c om try { newDate = dateFormat.parse(dateString); s = simpledateformat.format(newDate); } catch (ParseException e) { e.printStackTrace(); s = ""; } return s; }
From source file:Main.java
public static String getLeftDay(String date) { if ("".equals(date) || date == null) { return ""; }/*from w w w. j a v a 2 s . co m*/ Date cur = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", getLocale()); String curTime = sdf.format(cur); Date dt = new Date(); long day = 0; try { dt = sdf.parse(curTime); long l = Long.parseLong(date) - dt.getTime(); if (l > 0) { day = l / (24 * 60 * 60 * 1000); } else { day = 0; } } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NumberFormatException e) { e.printStackTrace(); } return Long.toString(day); }
From source file:com.b5m.user.frame.util.DateUtils.java
public static Date String2Date(String dateStr, String DateFormat) { SimpleDateFormat sdf = new SimpleDateFormat(DateFormat); try {/*from www .j av a 2 s . co m*/ return sdf.parse(dateStr); } catch (ParseException e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static String dateFormatter(String date) { // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); SimpleDateFormat sdf2 = new SimpleDateFormat("dd.MM.yyyy", new Locale("tr", "TR")); Date d;//from w ww .j av a 2 s .c om String formatdate = null; try { d = sdf.parse(date); formatdate = sdf2.format(d); } catch (ParseException ex) { return date; } return formatdate; }
From source file:com.alibaba.ims.platform.util.DateUtil.java
/** * ?//www .j av a 2 s . c o m * * @param dateStr * @return */ public static Date parse(String dateStr) { if (StringUtils.isBlank(dateStr)) { return null; } SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { return simpleDateFormat.parse(dateStr); } catch (ParseException e) { logger.error("Parse string to date error.", e); return null; } }
From source file:com.oa.product.action.MyDateUtils.java
/** * ???"yyyy-MM-dd HH:mm:ss"/*from ww w . ja va 2 s . c om*/ * * @param date * @return */ public static Date getDateStart(Date date) { if (date == null) { return null; } SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { date = sdf.parse(formatDate(date, "yyyy-MM-dd") + " 00:00:00"); } catch (ParseException e) { e.printStackTrace(); } return date; }
From source file:com.oa.product.action.MyDateUtils.java
/** * ????"yyyy-MM-dd HH:mm:ss"// w ww. j a va 2 s .c o m * * @param date * @return */ public static Date getDateEnd(Date date) { if (date == null) { return null; } SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { date = sdf.parse(formatDate(date, "yyyy-MM-dd") + " 23:59:59"); } catch (ParseException e) { e.printStackTrace(); } return date; }
From source file:Main.java
public static Date parseRFC822Date(String date) { Date result = null;/*from ww w . j ava 2 s. c o m*/ if (date.contains("PDT")) { date = date.replace("PDT", "PST8PDT"); } if (date.contains(",")) { // Remove day of the week date = date.substring(date.indexOf(",") + 1).trim(); } SimpleDateFormat format = RFC822Formatter.get(); for (int i = 0; i < RFC822DATES.length; i++) { try { format.applyPattern(RFC822DATES[i]); result = format.parse(date); break; } catch (ParseException e) { e.printStackTrace(); } } if (result == null) { Log.e(TAG, "Unable to parse feed date correctly"); } return result; }