List of utility methods to do Calendar String Parse
String | format(String time) format "yyyy-MM-dd HH:mm:ss" try { Calendar calendar = Calendar.getInstance(); calendar.setTime(parser.parse(time)); calendar.add(Calendar.HOUR, 3); return formatter.format(calendar.getTime()) .replaceAll("-", "/"); } catch (ParseException e) { e.printStackTrace(); ... |
Date | fromString(String dateString, String format) from String SimpleDateFormat inputFormat = new SimpleDateFormat(format); return inputFormat.parse(dateString); |
GregorianCalendar | parseCalendar(int year, int month, double day, TimeZone zone) Parses a date assuming all arguments are based on a Gregorian or Julian calendar. double hour = (day % 1) * 24; double minute = (hour % 1) * 60; double second = (minute % 1) * 60; double millisecond = (second % 1) * 1000; return parseCalendar(year, month, (int) day, (int) hour, (int) minute, (int) second, (int) Math.round(millisecond), zone); |
GregorianCalendar | parseCalendar(int year, int month, int day, int hour, int minute, int second, int millisecond, TimeZone zone) Parses a date assuming all arguments are based on a Gregorian calendar. GregorianCalendar calendar = new GregorianCalendar(zone); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month - 1); calendar.set(Calendar.DAY_OF_MONTH, (int) day); calendar.set(Calendar.HOUR_OF_DAY, (int) hour); calendar.set(Calendar.MINUTE, (int) minute); calendar.set(Calendar.SECOND, (int) second); calendar.set(Calendar.MILLISECOND, (int) Math.round(millisecond)); ... |
int | parseDA(Calendar c, String s, int off, int len) parse DA int pos = off; c.set(Calendar.YEAR, Integer.parseInt(s.substring(pos, pos += 4))); if (pos < len) { if (!Character.isDigit(s.charAt(pos))) ++pos; if (pos + 2 <= len) { c.set(Calendar.MONTH, Integer.parseInt(s.substring(pos, pos += 2)) - 1); ... |
int | parseTM(Calendar c, String s, int off, int len) parse TM int pos = off; String hours = s.substring(pos, pos += 2); c.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hours)); if (pos < len) { if (!Character.isDigit(s.charAt(pos))) { ++pos; if (pos + 2 <= len) { ... |
Calendar | getAsCalendar(String dateString) get As Calendar Calendar date = Calendar.getInstance();
date.setTime((Date) df.parse(dateString));
return date;
|
Calendar | getCalendarFromString(final String date) get Calendar From String final SimpleDateFormat inputFormat = new SimpleDateFormat( "E, MMMM dd, yyyy"); Date parsedDate = new Date(); try { parsedDate = inputFormat.parse(date.trim()); } catch (final ParseException e) { Log.e("DATE_PARSER", "Error: Impossible to parse input string to calendar.", ... |
Calendar | stringToCalendar(String date) string To Calendar Calendar calendar = Calendar.getInstance(); SimpleDateFormat dateformatter = new SimpleDateFormat( "dd/MM/yyyy HH:mm:ss"); try { calendar.setTime(dateformatter.parse(date)); } catch (ParseException e) { e.printStackTrace(); return calendar; |