Android Utililty Methods Calendar String Parse

List of utility methods to do Calendar String Parse


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


Stringformat(String time)
format "yyyy-MM-dd HH:mm:ss"
try {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.HOUR, 3);
    return formatter.format(calendar.getTime())
            .replaceAll("-", "/");
} catch (ParseException e) {
DatefromString(String dateString, String format)
from String
SimpleDateFormat inputFormat = new SimpleDateFormat(format);
return inputFormat.parse(dateString);
GregorianCalendarparseCalendar(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),
GregorianCalendarparseCalendar(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));
intparseDA(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)))
    if (pos + 2 <= len) {
                Integer.parseInt(s.substring(pos, pos += 2)) - 1);
intparseTM(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))) {
    if (pos + 2 <= len) {
CalendargetAsCalendar(String dateString)
get As Calendar
Calendar date = Calendar.getInstance();
date.setTime((Date) df.parse(dateString));
return date;
CalendargetCalendarFromString(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) {
            "Error: Impossible to parse input string to calendar.",
CalendarstringToCalendar(String date)
string To Calendar
Calendar calendar = Calendar.getInstance();
SimpleDateFormat dateformatter = new SimpleDateFormat(
        "dd/MM/yyyy HH:mm:ss");
try {
} catch (ParseException e) {
return calendar;