List of usage examples for java.text SimpleDateFormat parse
public Date parse(String source) throws ParseException
From source file:Main.java
public static String getDateByAddHour(String datetime, int minute) { String returnTime = null;//from www. j a va 2s .co m Calendar cal = new GregorianCalendar(); SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date; try { date = ft.parse(datetime); cal.setTime(date); cal.add(GregorianCalendar.MINUTE, minute); returnTime = getFormatDateTime(cal.getTime(), "yyyy-MM-dd HH:mm:ss"); } catch (ParseException e) { e.printStackTrace(); } return returnTime; }
From source file:Main.java
public static Date ParseDate(String str) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Date addTime = null;/* ww w .j av a2 s .c o m*/ try { addTime = dateFormat.parse(str); } catch (ParseException e) { e.printStackTrace(); } return addTime; }
From source file:Main.java
public static String getTwoDay(String sj1, String sj2) { SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd"); long day = 0; try {//from ww w. j ava2 s. c o m Date date = myFormatter.parse(sj1); Date mydate = myFormatter.parse(sj2); day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000); } catch (Exception e) { return ""; } return day + ""; }
From source file:Main.java
public static Date getDateByFormat(String strDate, String format) { SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format); Date date = null;//from w w w .jav a2 s . com try { date = mSimpleDateFormat.parse(strDate); } catch (ParseException e) { e.printStackTrace(); } return date; }
From source file:Main.java
public static Calendar parseCalendarString(String dateTimeString) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); Date date = null;//from ww w .ja va 2 s. co m 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 changeStringToDate1(String str) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); java.util.Date date6 = null;//from www.java 2 s.co m try { date6 = sdf.parse(str); return date6.toString(); } catch (ParseException e) { e.printStackTrace(); return ""; } }
From source file:Main.java
public static String convertDateFormat(String datetime) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss+0000"); Date testDate = null;/* ww w. ja v a 2 s .com*/ try { testDate = sdf.parse(datetime); } catch (Exception ex) { ex.printStackTrace(); } SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd"); return formatter.format(testDate); }
From source file:Main.java
public static Date convertDate(String dateToFormat) { SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"); Date date = null;/*from w w w .ja v a 2s . c om*/ try { date = dateFormat.parse(dateToFormat); } catch (java.text.ParseException e) { date = null; } return date; }
From source file:Main.java
public static boolean isCurrentTimeInBetween(String startTime, String endTime, String format) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format); try {//from w w w . j a v a2s . c o m Date startDate = simpleDateFormat.parse(startTime); long startTimeLong = startDate.getTime(); Date endDate = simpleDateFormat.parse(endTime); long endTimeLong = endDate.getTime(); Date currDate = new Date(System.currentTimeMillis()); String currTime = simpleDateFormat.format(currDate); currDate = simpleDateFormat.parse(currTime); long currentTime = currDate.getTime(); return currentTime >= startTimeLong && currentTime < endTimeLong; } catch (ParseException e) { e.printStackTrace(); } return false; }
From source file:Main.java
public static Date getDateByFormat(String strDate, String format) { SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format, Locale.CHINA); Date date = null;//from w w w. java 2s . com try { date = mSimpleDateFormat.parse(strDate); } catch (ParseException e) { e.printStackTrace(); } return date; }