Android Utililty Methods Calendar Create

List of utility methods to do Calendar Create

Description

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

Method

CalendarcreateDate(TimeZone timeZone, int year, int month, int day)
Creates a Calendar instance for the given year, month (1-based), and day (1-based) in the given time zone
Calendar date = Calendar.getInstance(timeZone);
date.clear();
date.set(year, month - 1, day); 
return date;
CalendarcreateDate(TimeZone timeZone, int year, int month, int day, int hour, int minute, int second)
Creates a Calendar instance for the given year, month (1-based), day (1-based), hour, minute and second in the given time zone
Calendar date = Calendar.getInstance(timeZone);
date.set(year, month - 1, day, hour, minute, second); 
date.set(Calendar.MILLISECOND, 0);
return date;
CalendarcreateDate(int year, int month, int day)
Creates a Calendar instance for the given year, month (1-based), and day (1-based) in the default time zone
Calendar date = Calendar.getInstance();
date.clear();
date.set(year, month - 1, day); 
return date;
CalendarcreateDate(int year, int month, int day, int hour, int minute, int second)
Creates a Calendar instance for the given year, month (1-based), day (1-based), hour, minute and second in the default time zone
Calendar date = Calendar.getInstance();
date.set(year, month - 1, day, hour, minute, second); 
date.set(Calendar.MILLISECOND, 0);
return date;
CalendargetCalendar()
get Calendar
setDefaultTimeZoneToVietnam();
Calendar today = Calendar.getInstance();
today.setTime(new Date());
return today;
CalendargetCalendar(int year, int month, int dayOfMonth, int hourOfDay, int minute)
get Calendar
Calendar startRollingTime = Calendar.getInstance();
startRollingTime.set(Calendar.YEAR, year);
startRollingTime.set(Calendar.MONTH, month);
startRollingTime.set(Calendar.DAY_OF_MONTH, dayOfMonth);
startRollingTime.set(Calendar.HOUR_OF_DAY, hourOfDay);
startRollingTime.set(Calendar.MINUTE, minute);
startRollingTime.set(Calendar.SECOND, 00);
return startRollingTime;
...
DategetCurrentTime()
get Current Time
return getCalendar().getTime();
StringgetDateWithFormat(int year, int month, int day)
get Date With Format
SimpleDateFormat dateFormat = new SimpleDateFormat(
        "EEEE, MMMM d, yyyy");
return dateFormat.format(new GregorianCalendar(year, (month - 1),
        day).getTime());
StringgetDateWithShortFormat(int year, int month, int day)
get Date With Short Format
SimpleDateFormat dateFormat = new SimpleDateFormat(
        "EEE, MMM d, yyyy");
return dateFormat.format(new GregorianCalendar(year, (month - 1),
        day).getTime());
longgetMilliSeconds(int year, int month, int day, int hour, int minute)
get Milli Seconds
Calendar c = Calendar.getInstance();
c.setTime(new GregorianCalendar(year, (month - 1), day, hour,
        minute).getTime());
return c.getTimeInMillis();