|
Rakesh API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.Calendar
java.util.GregorianCalendar
org.rakeshv.utils.Calendar
public class Calendar
A wrapper around java.util.GregorianCalendar. Setting
the TimeZone of this Calendar will
automatically adjust the underlying Date by
offsetting from the existing TimeZone.
Java always represents the time in UTC. This can sometimes be incovenient especially when dealing with RDBMS systems, where fetching a date/time/timestamp value will return a value with the millisecond value that represents the value in current TimeZone as opposed to UTC. This class can be used to conveniently correct the internal time represented.
The following code snippet shows a way of using this class:
import java.util.Calendar;
import java.util.TimeZone;
Calendar local = org.rakeshv.utils.Calendar.getInstance();
System.out.println( "local " + local.getTime() );
Calendar utc = org.rakeshv.utils.Calendar.getInstance( TimeZone.getTimeZone( "UTC" ) );
System.out.println( "utc " + utc.getTime() );
Calendar pst = org.rakeshv.utils.Calendar.getInstance( TimeZone.getTimeZone( "America/Los_Angeles" ) );
System.out.println( "pst " + pst.getTime() );
pst.setTimeZone( TimeZone.getDefault() );
System.out.println( "pst in local " + pst.getTime() );
Copyright 2004-2006 Rakesh Vidyadharan
| Field Summary | |
|---|---|
static int |
ROUND_AUTO
A contant used to indicate that the MINUTE of this
calendar is to be rounded automatically using normal rounding
rules to the nearest multiple of 5. |
static int |
ROUND_DOWN
A contant used to indicate that the MINUTE of this
calendar is to be rounded down to the nearest multiple of 5. |
static int |
ROUND_UP
A contant used to indicate that the MINUTE of this
calendar is to be rounded up to the nearest multiple of 5. |
| Fields inherited from class java.util.GregorianCalendar |
|---|
AD, BC |
| Fields inherited from class java.util.Calendar |
|---|
AM, AM_PM, APRIL, areFieldsSet, AUGUST, DATE, DAY_OF_MONTH, DAY_OF_WEEK, DAY_OF_WEEK_IN_MONTH, DAY_OF_YEAR, DECEMBER, DST_OFFSET, ERA, FEBRUARY, FIELD_COUNT, fields, FRIDAY, HOUR, HOUR_OF_DAY, isSet, isTimeSet, JANUARY, JULY, JUNE, MARCH, MAY, MILLISECOND, MINUTE, MONDAY, MONTH, NOVEMBER, OCTOBER, PM, SATURDAY, SECOND, SEPTEMBER, SUNDAY, THURSDAY, time, TUESDAY, UNDECIMBER, WEDNESDAY, WEEK_OF_MONTH, WEEK_OF_YEAR, YEAR, ZONE_OFFSET |
| Constructor Summary | |
|---|---|
Calendar()
Constructs a Calendar with the default time zone and locale. |
|
Calendar(java.util.Locale locale)
Constructs a Calendar based on the current time in the default time zone with the given locale. |
|
Calendar(java.util.TimeZone timeZone)
Constructs a Calendar based on the current time in the given time zone with the default locale. |
|
Calendar(java.util.TimeZone timeZone,
java.util.Locale locale)
Constructs a calendar with the specified time zone and locale. |
|
| Method Summary | |
|---|---|
static java.util.Calendar |
getInstance()
Gets a calendar using the default time zone and locale. |
static java.util.Calendar |
getInstance(java.util.Locale locale)
Gets a calendar using the default time zone and specified locale. |
static java.util.Calendar |
getInstance(java.util.TimeZone timeZone)
Gets a calendar using the specified time zone and default locale. |
static java.util.Calendar |
getInstance(java.util.TimeZone timeZone,
java.util.Locale locale)
Gets a calendar with the specified time zone and locale. |
Calendar |
roundMinutes(int minInterval,
int rounding)
Round the MINUTE part of this calendar to the nearest
5 minute mark. |
void |
set(int field,
int value)
Sets the given calendar field to the given value. |
void |
setTimeZone(java.util.TimeZone timeZone)
Sets the time zone with the given time zone value. |
| Methods inherited from class java.util.GregorianCalendar |
|---|
add, clone, computeFields, computeTime, equals, getActualMaximum, getActualMinimum, getGreatestMinimum, getGregorianChange, getLeastMaximum, getMaximum, getMinimum, getTimeZone, hashCode, isLeapYear, roll, roll, setGregorianChange |
| Methods inherited from class java.util.Calendar |
|---|
after, before, clear, clear, compareTo, complete, get, getAvailableLocales, getFirstDayOfWeek, getMinimalDaysInFirstWeek, getTime, getTimeInMillis, internalGet, isLenient, isSet, set, set, set, setFirstDayOfWeek, setLenient, setMinimalDaysInFirstWeek, setTime, setTimeInMillis, toString |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int ROUND_UP
MINUTE of this
calendar is to be rounded up to the nearest multiple of 5. Used
by the roundMinutes(int, int) method.
1
public static final int ROUND_DOWN
MINUTE of this
calendar is to be rounded down to the nearest multiple of 5. Used
by the roundMinutes(int, int) method.
2
public static final int ROUND_AUTO
MINUTE of this
calendar is to be rounded automatically using normal rounding
rules to the nearest multiple of 5. Used by the
roundMinutes(int, int) method.
3
| Constructor Detail |
|---|
public Calendar()
public Calendar(java.util.TimeZone timeZone)
time for the
calendar is set to the equivalent for the specified time zone
based upon the system time in the system time zone.
timeZone - - The TimeZone to use.setTimeZone( TimeZone )public Calendar(java.util.Locale locale)
locale - - The Locale to use.
public Calendar(java.util.TimeZone timeZone,
java.util.Locale locale)
time for the calendar is set to the equivalent
for the specified time zone based upon the system time in the
system time zone.
timeZone - - The TimeZone to use.locale - - The Locale to use.setTimeZone( TimeZone )| Method Detail |
|---|
public static java.util.Calendar getInstance()
Calendar.Calendar()public static java.util.Calendar getInstance(java.util.TimeZone timeZone)
timeZone - - The TimeZone to use.
Calendar.Calendar( TimeZone )public static java.util.Calendar getInstance(java.util.Locale locale)
locale - - The Locale to use.
Calendar.Calendar( Locale )
public static java.util.Calendar getInstance(java.util.TimeZone timeZone,
java.util.Locale locale)
timeZone - - The TimeZone to use.locale - - The Locale to use.
Calendar.Calendar( TimeZone, Locale )public void setTimeZone(java.util.TimeZone timeZone)
time value is modified by the appropriate
offset based upon the current time zone.
setTimeZone in class java.util.GregorianCalendar
public void set(int field,
int value)
HOUR and HOUR_OF_DAY to
apply proper correction when the timeZone is not
the local timeZone.
set in class java.util.Calendarfield - The given calendar field.value - The value to be set for the given calendar field.
java.lang.ArrayIndexOutOfBoundsException - if the specified field is
out of range (field < 0 || field >= FIELD_COUNT).
In non-lenient mode.
public Calendar roundMinutes(int minInterval,
int rounding)
MINUTE part of this calendar to the nearest
5 minute mark. This is useful for creating drop-down menus in
user interface components.
minInterval - The interval to use for rounding. The value
must be at least 5 (it will be corrected to 5 otherwise), and
should be a multiple of 5 (will be corrected to a multiple of
5 otherwise).rounding - A constant used to indicate the direction in which
the rounding is to be performed. Specify one of ROUND_UP, ROUND_DOWN, or ROUND_AUTO.
|
Rakesh API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||