Java Utililty Methods Calendar Parse

List of utility methods to do Calendar Parse

Description

The list of methods to do Calendar Parse are organized into topic(s).

Method

CalendarconvertStringToCalendar(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();
...
CalendargetCalendar(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));
...
CalendargetCalendarObject(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;
...
Calendarstr2Calendar(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) {
...
Calendarstr2Calendar(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;
Calendarstring2Calendar(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));
...
StringstringCalendar(Calendar cal)
string Calendar
if (cal != null) {
    return sdf2.format(cal.getTime());
return "";
CalendarstringToCalendar(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;
GregorianCalendarstringToCalendar(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;
CalendartoCalendar(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;
...