List of usage examples for java.text SimpleDateFormat parse
public Date parse(String source) throws ParseException
From source file:Main.java
public static Long dateStrToLong(String str) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date addTime = null;//from w w w. j a v a2 s. c o m try { addTime = dateFormat.parse(str); } catch (ParseException e) { e.printStackTrace(); } return addTime.getTime(); }
From source file:Main.java
public static boolean showMessageTime(String currentTime, String prevTime) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try {/*from w ww.java2 s . c o m*/ Date currentDate = sdf.parse(currentTime); Date prevDate = sdf.parse(prevTime); if (currentDate.getTime() - prevDate.getTime() >= 300000) { return true; } } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:Main.java
public static boolean judgeTime2Time(String time1, String time2) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); try {/*from w w w. j av a2 s .co m*/ Date date1 = sdf.parse(time1); Date date2 = sdf.parse(time2); long l1 = date1.getTime() / 1000; long l2 = date2.getTime() / 1000; if (l2 - l1 > 0) { return true; } else { return false; } } catch (ParseException e) { e.printStackTrace(); } return false; }
From source file:Main.java
/** * templete: FORMAT_STR -> Date/*from www. j av a2 s .c o m*/ * * @param str * @param format * @return */ public static Date str2date(String str, String format) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format); Date date = null; try { date = simpleDateFormat.parse(str); } catch (ParseException e) { e.printStackTrace(); } return date; }
From source file:Main.java
public static Date convertStringToDate(String dateString) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-ddTHH:mm:ss"); Date date = null;/* w ww.j ava 2 s .c om*/ try { date = format.parse(dateString); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return date; }
From source file:com.enseval.ttss.util.Util.java
public static Date toDate(String tgl) { Date ret = null;//www .j a v a 2s . co m SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); try { ret = formatter.parse(tgl); } catch (ParseException ex) { Logger.getLogger(Util.class.getName()).log(Level.SEVERE, null, ex); } return ret; }
From source file:Main.java
public static String formatTimestamp(String in) { SimpleDateFormat formater = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss"); Date date = null;/*from w w w . j a va 2s .co m*/ try { date = formater.parse(in); } catch (ParseException e) { return ""; } SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); return sdf.format(date); }
From source file:Main.java
public static String getStringByFormat(String strDate, String format, String outFormat) { String mDateTime = null;//from w w w .j a va2 s .c o m try { Calendar c = new GregorianCalendar(); SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format); c.setTime(mSimpleDateFormat.parse(strDate)); SimpleDateFormat mSimpleDateFormat2 = new SimpleDateFormat(outFormat); mDateTime = mSimpleDateFormat2.format(c.getTime()); } catch (Exception e) { e.printStackTrace(); } return mDateTime; }
From source file:Main.java
public static String getDate(String s, String format1, String format2) throws java.text.ParseException { if (s == "") return ""; SimpleDateFormat form1 = new SimpleDateFormat(format1); SimpleDateFormat form2 = new SimpleDateFormat(format2); Date date = form1.parse(s); return form2.format(date); }
From source file:Main.java
public static long getLongForPresentDate(String date) { SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy", Locale.US); long time = 0; try {/* www . jav a 2s . c om*/ time = sdf.parse(date).getTime(); } catch (ParseException e) { e.printStackTrace(); } return time; }