List of usage examples for java.text SimpleDateFormat parse
public Date parse(String source) throws ParseException
From source file:Main.java
/** * Converts a string representation of a date to that date * * @param dateString The string to parse * @param format The format to parse the string with * @return The date, or null/*from w w w . j a va 2 s.c om*/ */ public static Date stringToDate(String dateString, String format) { if (dateString == null) { return null; } SimpleDateFormat df = new SimpleDateFormat(format, Locale.US); try { return df.parse(dateString); } catch (ParseException e) { e.printStackTrace(); } return null; }
From source file:com.heren.turtle.server.utils.SampleDateUtils.java
public static Date getDate(String dateStr, String pattern) { SimpleDateFormat sdf = new SimpleDateFormat(pattern); Date parseDate = null;//from w w w. j a v a2s. c om try { parseDate = sdf.parse(dateStr); } catch (ParseException e) { e.printStackTrace(); } return parseDate; }
From source file:Main.java
public static long getTimeInLong(String timeString) throws ParseException { SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss.SS"); String base = "00:00:00.00"; Date baseTime = format.parse(base); Date targetTime = format.parse(timeString); return targetTime.getTime() - baseTime.getTime(); }
From source file:Main.java
public static String getStringByOffset(String strDate, String format, int calendarField, int offset) { String mDateTime = null;/* w w w . j a va 2s .c o m*/ try { Calendar c = new GregorianCalendar(); SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format); c.setTime(mSimpleDateFormat.parse(strDate)); c.add(calendarField, offset); mDateTime = mSimpleDateFormat.format(c.getTime()); } catch (ParseException e) { e.printStackTrace(); } return mDateTime; }
From source file:Main.java
public static String getTime(String user_time) { String re_time = null;/*w w w .ja v a 2s.c om*/ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date d; try { d = sdf.parse(user_time); long l = d.getTime(); String str = String.valueOf(l); re_time = str.substring(0, 10); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return re_time; }
From source file:Main.java
public static Date stringToTime(String paramString) { SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try {//from w w w. j av a 2 s . c o m Date localDate = localSimpleDateFormat.parse(paramString); return localDate; } catch (ParseException localParseException) { } return null; }
From source file:Main.java
public static String getStringByOffset(String strDate, String format, int calendarField, int offset) { String mDateTime = null;/*from w w w. j a v a2 s . com*/ try { Calendar c = new GregorianCalendar(); SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format, Locale.CHINA); c.setTime(mSimpleDateFormat.parse(strDate)); c.add(calendarField, offset); mDateTime = mSimpleDateFormat.format(c.getTime()); } catch (ParseException e) { e.printStackTrace(); } return mDateTime; }
From source file:Main.java
public static Date getDate(String crisisDate) { try {/*from w w w.j a v a 2 s .c om*/ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm"); Date date = (Date) formatter.parse(crisisDate); Calendar cal = Calendar.getInstance(); cal.setTime(date); return cal.getTime(); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:Main.java
public static Date parseDateTime(String dateString) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date result = null;/*w w w .jav a2 s.com*/ try { result = df.parse(dateString); } catch (Exception e) { } return result; }
From source file:Main.java
@SuppressLint("SimpleDateFormat") public static Date StringToDate(String str) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); Date date = null;/*from ww w.j a v a 2s. c o m*/ try { date = sdf.parse(str); } catch (java.text.ParseException e) { e.printStackTrace(); } return date; }