List of utility methods to do Calendar Parse
Calendar | convertStringToCalendar(String time) convert String To Calendar SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar calendarDate = Calendar.getInstance(); Date dateObj = null; try { dateObj = sdf.parse(time); calendarDate.setTime(dateObj); } catch (ParseException e) { e.printStackTrace(); ... |
Calendar | getCalendar(Object source) get Calendar String d = getString(source); Calendar c = Calendar.getInstance(); TimeZone t = TimeZone.getTimeZone("Etc/Universal"); c.setTimeZone(t); SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); s.setTimeZone(t); try { c.setTime(s.parse(d)); ... |
Calendar | getCalendarObject(String value, boolean hasMills) get Calendar Object try { Calendar calendar = Calendar.getInstance(); if (hasMills) { calendar.setTime(SIMPLE_DATE_FORMAT_MILLS.parse(value)); } else { calendar.setTime(SIMPLE_DATE_FORMAT.parse(value)); return calendar; ... |
Calendar | str2Calendar(String pString) Converts a string to a Calendar object Calendar cal = null; if (pString != null) { try { SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); Date d = sdf.parse(pString); cal = Calendar.getInstance(); cal.setTime(d); } catch (ParseException e) { ... |
Calendar | str2Calendar(String str, String format) str Calendar Date date = str2Date(str, format); if (date == null) { return null; Calendar c = Calendar.getInstance(); c.setTime(date); return c; |
Calendar | string2Calendar(String data) string Calendar SimpleDateFormat sdf1 = new SimpleDateFormat("dd/MM/yyyy"); SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd"); Calendar cal = Calendar.getInstance(); try { if (data.contains("/")) cal.setTime(sdf1.parse(data)); else cal.setTime(sdf2.parse(data)); ... |
String | stringCalendar(Calendar cal) string Calendar if (cal != null) { return sdf2.format(cal.getTime()); return ""; |
Calendar | stringToCalendar(final String str, String format, boolean lenient) Convert string to Calendar. SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.FRANCE); sdf.setLenient(lenient); Date date = sdf.parse(str); Calendar cal = Calendar.getInstance(); cal.setTime(date); return cal; |
GregorianCalendar | stringToCalendar(String fecha, String formato) entrega un objetod el tipo GregorianCalendar con la fecha indicada fecha = nullToBlank(fecha); GregorianCalendar gc = new GregorianCalendar(); SimpleDateFormat df = new SimpleDateFormat(formato); gc.setTime(df.parse(fecha)); return gc; |
Calendar | toCalendar(Object value, String format) Convert the specified object into a Calendar. if (value == null) return null; if (value instanceof Calendar) return (Calendar) value; if (value instanceof Date) { Calendar calendar = Calendar.getInstance(); calendar.setTime((Date) value); return calendar; ... |