List of usage examples for java.text DateFormat parse
public Date parse(String source) throws ParseException
From source file:DateOutils.java
public static Date stringToDate(String d) throws ParseException { DateFormat formatter = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy", Locale.UK); Date date = (Date) formatter.parse(d); return date;//from w ww. j a va2 s. co m }
From source file:Main.java
public static String formatPublishedAt(String str) { // yyyy-MM-dd'T'HH:mm:ss.SSSZ try {//from w ww. j a v a2s .c om DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); Date date = format.parse(str); DateFormat format2 = new SimpleDateFormat("yyyy/MM/dd"); return format2.format(date); } catch (ParseException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
public static Date stringToDate3(String date) throws ParseException { DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.ENGLISH); Date _date = format.parse(date); return _date; }
From source file:Main.java
public static Date strToDate(String dateStr, String format) { Date date = null;/*from w w w .j a v a2s .c o m*/ if (dateStr != null && (!dateStr.equals(""))) { DateFormat df = new SimpleDateFormat(format); try { date = df.parse(dateStr); } catch (ParseException e) { e.printStackTrace(); } } return date; }
From source file:Main.java
/** * The snapped start how long//from w w w . ja va 2 s .co m * * @param startTime * @param currentTime * @return */ public static boolean isStart(String startTime, String currentTime) { Date current = null; Date start = null; try { DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); current = format.parse(currentTime); start = format.parse(startTime); } catch (ParseException e) { return false; } if (current != null && start != null) { return current.after(start); } return false; }
From source file:Main.java
public static int getWeekNumber(String strDate, String inFormat) { Calendar calendar = new GregorianCalendar(); DateFormat df = new SimpleDateFormat(inFormat); try {//from ww w.j av a 2 s . co m calendar.setTime(df.parse(strDate)); } catch (Exception e) { return -1; } int intTemp = calendar.get(Calendar.DAY_OF_WEEK) - 1; return intTemp; }
From source file:Main.java
public static int days(String day1, String day2, String format) { DateFormat df = new SimpleDateFormat(format); long days = 0; try {// w ww . j a v a 2 s . c o m Date d1 = df.parse(day1); Date d2 = df.parse(day2); long diff = Math.abs(d1.getTime() - d2.getTime()); days = diff / (1000 * 60 * 60 * 24); } catch (Exception e) { } return (int) days; }
From source file:Main.java
/** * The end of the rush to buy whether//from ww w.j a v a 2 s . com * * @param endTime * @param currentTime * @return Has been completed */ public static boolean isOver(String endTime, String currentTime) { Date current = null; Date end = null; try { DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); current = format.parse(currentTime); end = format.parse(endTime); } catch (IllegalArgumentException e) { return false; } catch (ParseException e) { return false; } if (current != null && end != null) { return current.after(end); } return false; }
From source file:Main.java
public static int getMonth(String sDate) { DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Date d = null;/*from w ww. j ava2s . co m*/ try { d = df.parse(sDate); } catch (ParseException e) { e.printStackTrace(); } if (d == null) { return 0; } return d.getMonth(); }
From source file:Main.java
public static int getYear(String sDate) { DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Date d = null;/* w w w . ja v a2s . c o m*/ try { d = df.parse(sDate); } catch (ParseException e) { e.printStackTrace(); } if (d == null) { return 1971; } return d.getYear() + 1900; }