List of usage examples for java.text SimpleDateFormat parse
public Date parse(String source) throws ParseException
From source file:Main.java
public static Date string2Date(String sd, String formato) { //formato = "yyyy-MM-dd'T'HH:mm:ss'Z'"; //"Thu Jul 11 12:40:18 GMT-03:00 2013" //"EE MMM dd HH:mm:ss z YYYY" SimpleDateFormat format = new SimpleDateFormat(formato); try {/*from w w w . j av a 2 s .c o m*/ Date date = (Date) format.parse(sd); return date; } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:Main.java
public static int timeCompare(String str1, String str2) { try {//w w w. j a va2s . c o m SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); java.util.Date begin = dfs.parse(str1); java.util.Date end = dfs.parse(str2); long between = end.getTime() - begin.getTime(); if (between > 0) { return 1; } else if (between == 0) { return 0; } else { return -1; } } catch (Exception e) { return 1; } }
From source file:Main.java
public static boolean isSameDay(String time1, String time2) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); try {//from ww w . j av a 2 s . c om Date date1 = sdf.parse(time1); Date date2 = sdf.parse(time2); return sdf.format(date1).equals(sdf.format(date2)); } catch (ParseException e) { e.printStackTrace(); } return false; }
From source file:Main.java
public static long getBetweenDiff(String startTime, String endTime, String format) { long diff = 0; SimpleDateFormat ft = new SimpleDateFormat(format); try {//www. j ava 2 s . co m Date startDate = ft.parse(startTime); Date endDate = ft.parse(endTime); diff = startDate.getTime() - endDate.getTime(); diff = diff / 1000; } catch (ParseException e) { e.printStackTrace(); } return diff; }
From source file:Main.java
public static Date fromStringToDate(String string) { SimpleDateFormat ft = new SimpleDateFormat("dd.MM.yyyy"); Date date = null;//from w w w. ja v a2 s . c o m try { date = ft.parse(string); } catch (ParseException e) { Log.e("PARSEEXC", "DATEPARSINGFAILED"); } return date; }
From source file:Main.java
public static Date stringDateToDate(String StrDate) { Date dateToReturn = null;// www. ja v a 2 s. c om SimpleDateFormat dateFormat = new SimpleDateFormat(DATEFORMAT); try { dateToReturn = (Date) dateFormat.parse(StrDate); } catch (ParseException e) { e.printStackTrace(); } return dateToReturn; }
From source file:Main.java
public static String ymdhm2Timestamp(String dateString) throws ParseException { String timeStamp = null;//from w w w .j av a 2 s . c om SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH/mm"); Date d; try { d = sdf.parse(dateString); long l = d.getTime() / 1000; timeStamp = String.valueOf(l); } catch (ParseException e) { e.printStackTrace(); } return timeStamp; }
From source file:Main.java
public static Date dateFormat(String arcTime, String format) { SimpleDateFormat formatSrc = new SimpleDateFormat(format); Date date = null;//w w w . j a v a 2 s .c o m try { date = formatSrc.parse(arcTime); } catch (ParseException e) { e.printStackTrace(); } return date; }
From source file:Main.java
public static long getTempTime(String time) { try {/*from ww w . j a v a2 s .c om*/ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = simpleDateFormat.parse(time); long tempTime = date.getTime(); return tempTime; } catch (ParseException e) { e.printStackTrace(); } return 0; }
From source file:Main.java
public static Date getDateByFormatDate(String dateString, String format) { SimpleDateFormat dateFormat = new SimpleDateFormat(format); Date date = null;// ww w . j av a 2s .c om try { date = dateFormat.parse(dateString); } catch (ParseException exception) { exception.printStackTrace(); } return date; }