List of usage examples for java.text ParsePosition ParsePosition
public ParsePosition(int index)
From source file:Main.java
public static String stringDateToString(String format, String toFormat, String dateString) { ParsePosition position = new ParsePosition(0); SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format, Locale.getDefault()); SimpleDateFormat StringDateFormat = new SimpleDateFormat(toFormat); Date dateValue = null;/*from ww w.ja v a 2 s . c om*/ String data = ""; try { dateValue = simpleDateFormat.parse(dateString, position); data = StringDateFormat.format(dateValue); } catch (Exception e) { e.printStackTrace(); } return data; }
From source file:Main.java
public static String getNextDateByNum(String s, int i) { SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyyMMdd"); java.util.Date date = simpledateformat.parse(s, new ParsePosition(0)); Calendar calendar = Calendar.getInstance(); calendar.setTime(date);//from ww w . j a v a 2s . com calendar.add(5, i); date = calendar.getTime(); s = simpledateformat.format(date); return s; }
From source file:Main.java
public static String getNextDateByYear(String s, int i) { SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyyMMdd"); java.util.Date date = simpledateformat.parse(s, new ParsePosition(0)); Calendar calendar = Calendar.getInstance(); calendar.setTime(date);//from w ww .j a v a2 s .c o m calendar.add(Calendar.YEAR, i); date = calendar.getTime(); s = simpledateformat.format(date); return s; }
From source file:Main.java
public static String getNextDateByMonth(String s, int i) { SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyyMMdd"); java.util.Date date = simpledateformat.parse(s, new ParsePosition(0)); Calendar calendar = Calendar.getInstance(); calendar.setTime(date);//from ww w . ja v a 2s . c o m calendar.add(2, i); date = calendar.getTime(); s = simpledateformat.format(date); return s; }
From source file:Main.java
public static String timeAgo(String iso8601) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); ParsePosition position = new ParsePosition(0); Date date = null;/*from w w w . j av a 2 s . com*/ try { date = simpleDateFormat.parse(iso8601.replaceFirst("Z", "+00:00"), position); } catch (Exception e) { System.out.println("could not parese date"); } String timeAgo = date == null ? "" : DateUtils.getRelativeTimeSpanString(date.getTime()).toString(); return timeAgo; }
From source file:Main.java
public static Date getNowDateShort() { Date currentTime = new Date(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); String dateString = formatter.format(currentTime); ParsePosition pos = new ParsePosition(8); Date currentTime_2 = formatter.parse(dateString, pos); return currentTime_2; }
From source file:Main.java
public static Date getNowDate() { Date currentTime = new Date(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); String dateString = formatter.format(currentTime); ParsePosition pos = new ParsePosition(8); Date currentTime_2 = formatter.parse(dateString, pos); return currentTime_2; }
From source file:Main.java
/** * Convert String date to Date type//from w w w .ja va 2 s.co m * * @param date * String date * @param format * date format * @return Date */ public static Date stringToDate(String date, String format) { if (date == null) return null; ParsePosition pos = new ParsePosition(0); SimpleDateFormat simpledateformat = new SimpleDateFormat(format); Date stringDate = simpledateformat.parse(date, pos); return stringDate; }
From source file:Main.java
/** * Parse the Date String in mySQL format into date object * /*w ww. ja v a 2 s . com*/ * @param SQLDate the date String in SQL format ("yyyy-MM-dd HH:mm:ss") * @return The date object corresponding to SQLDate */ public static Date parseSQLDate(String SQLDate) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); sdf.setTimeZone(TimeZone.getTimeZone("GMT")); return sdf.parse(SQLDate, new ParsePosition(0)); }
From source file:Main.java
public static String stringDateToString(String format, String dateString) { ParsePosition position = new ParsePosition(0); SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format, Locale.getDefault()); SimpleDateFormat StringDateFormat = new SimpleDateFormat(format); Date dateValue = null;// ww w .jav a2 s . c o m String data = ""; try { dateValue = simpleDateFormat.parse(dateString, position); data = StringDateFormat.format(dateValue); } catch (Exception e) { e.printStackTrace(); } return data; }