List of usage examples for java.text SimpleDateFormat parse
public Date parse(String source) throws ParseException
From source file:Main.java
public static long getStringToDate(String time, String format) { SimpleDateFormat sdf = new SimpleDateFormat(format); Date date = new Date(); try {//from w ww . jav a 2 s. c om date = sdf.parse(time); } catch (ParseException e) { e.printStackTrace(); } return date.getTime(); }
From source file:Main.java
public static Date parseDatetime(String datetime, String pattern) throws ParseException { SimpleDateFormat format = (SimpleDateFormat) datetimeFormat.clone(); format.applyPattern(pattern);//from ww w. ja v a 2s. co m return format.parse(datetime); }
From source file:Main.java
public static String formatToDate(String datetime) { String str = ""; SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA); try {/*from ww w. java 2 s . c o m*/ str = format.format(format.parse(datetime)); } catch (ParseException e) { e.printStackTrace(); } return str; }
From source file:Main.java
public static int compare(String s1, String s2) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA); try {/* w w w . ja v a2 s .co m*/ Date d1 = format.parse(s1); Date d2 = format.parse(s2); return d1.compareTo(d2); } catch (ParseException e) { e.printStackTrace(); } return -1; }
From source file:Main.java
public static int dayForWeek(String pTime) throws Exception { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Calendar c = Calendar.getInstance(); c.setTime(format.parse(pTime)); int dayForWeek = 0; return c.get(Calendar.DAY_OF_WEEK); }
From source file:Main.java
public static Date getDateFromString(String format, String dateString) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat(format); sdf.setTimeZone(TimeZone.getTimeZone("GMT")); return sdf.parse(dateString); }
From source file:Main.java
public static String formatTime(String time) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try {/*from w w w . ja v a 2 s. co m*/ return formatter.format(formatter.parse(time)); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); return ""; } }
From source file:Main.java
public static Date stringToDate(String str) { Date date = null;// ww w .j a v a 2s . com SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); try { date = formatter.parse(str); return date; } catch (Exception e) { return null; } }
From source file:Main.java
public static Date parseDateString(String dateString) { // "2014-04-26 09:00:22" Date date = null;// ww w .j av a2 s . c om SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.US); try { date = dateFormat.parse(dateString); } catch (ParseException e) { e.printStackTrace(); } return date; }
From source file:Main.java
public static String StandardFormatStr(String str) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try {//from w w w. ja v a 2s .co m Date d = sdf.parse(str); long timeStamp = d.getTime(); long curTime = System.currentTimeMillis() / (long) 1000; long time = curTime - timeStamp / 1000; return time / 60 + ""; } catch (ParseException e) { e.printStackTrace(); } return null; }