|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.rim.device.api.util.DateTimeUtilities
public final class DateTimeUtilities
Provides access to date/time operations.
Note that time keeping on the Device uses one millisecond ticks as the base increment. The Device maintains absolute time keeping in ticks since the origin time (or midnight Jan 1, 1970).
Field Summary | ||
---|---|---|
static String |
GMT
String used for obtaining the base GMT timezone via TimeZone.getTimeZone() . |
|
static long |
GUID_DATE_CHANGED
GUID for the global event sent when the date changes. |
|
static long |
GUID_TIMEZONE_CHANGED
GUID for the global event sent when the timezone changes. |
|
static int |
ONEDAY
Number of ticks in one day. |
|
static int |
ONEHOUR
Number of ticks in one hour. |
|
static int |
ONEMINUTE
Number of ticks in one minute. |
|
static long |
ONEMONTH
Number of ticks in one one month or 4 weeks. |
|
static int |
ONESECOND
Number of ticks in one second. |
|
static int |
ONEWEEK
Number of ticks in one week. |
|
static long |
ONEYEAR
Number of ticks in one year or 365 days. |
Method Summary | ||
---|---|---|
static long |
copyCalendar(Calendar source,
Calendar destination)
Copies a date from one calendar to another. |
|
static void |
formatElapsedTime(long time,
StringBuffer sb,
boolean reset)
Retrieves string representation of duration into buffer. |
|
static int[] |
getCalendarFields(Calendar cal,
int[] fields)
Extracts fields from a calendar object. |
|
static Calendar |
getDate(int millisSinceMidnight)
Retrieves date relative to midnight on current day. |
|
static Calendar |
getNextDate(int millisSinceMidnight)
Retrieves future date relative to midnight on current day. |
|
static int |
getNumberOfDaysInMonth(int month,
int year)
Returns the number of days in the month specified |
|
static int |
getWeekOfYear(Calendar calendar,
long date,
int firstDayofWeek)
Returns the number of the week in the year of the specified date. |
|
static boolean |
isLeapYear(int year)
Determines if a year is a leap year using the rules defined in Wikipedia. |
|
static boolean |
isSameDate(long date1,
long date2)
Determine if two dates fall on the same calendar date using default TimeZone |
|
static boolean |
isSameDate(long date1,
long date2,
TimeZone tz1,
TimeZone tz2)
Determine if two dates fall on the same calendar date |
|
static boolean |
isSameDate(long date1,
long date2,
TimeZone tz1,
TimeZone tz2,
Calendar cal)
Determine if two dates fall on the same calendar date |
|
static boolean |
isWeekend()
Determines if the current day is a weekend day. |
|
static boolean |
isWeekend(Calendar cal)
Determines if provided date falls on a weekend. |
|
static boolean |
isWeekend(long date)
Determines if the specified long integer date falls on a weekend. |
|
static void |
setCalendarFields(Calendar cal,
int[] fields)
Sets field values for a calendar object. |
|
static void |
zeroCalendarTime(Calendar calendar)
Resets the calendar object to the start of its day. (00:00:00:00, hh:mm:ss:mm) |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final long GUID_DATE_CHANGED
public static final long GUID_TIMEZONE_CHANGED
public static final int ONESECOND
public static final int ONEMINUTE
public static final int ONEHOUR
public static final int ONEDAY
public static final int ONEWEEK
public static final long ONEMONTH
public static final long ONEYEAR
public static String GMT
TimeZone.getTimeZone()
.
Method Detail |
---|
public static boolean isWeekend()
public static boolean isWeekend(long date)
date
- Date to test, measured in ticks since the origin.
IllegalArgumentException
- Thrown if the specified date value is
less than 0.public static boolean isWeekend(Calendar cal)
cal
- Date to test.
public static Calendar getNextDate(int millisSinceMidnight)
Provided a number of ticks, this method returns either a time today (if the time would still be in the future relative to the current time), or a time tomorrow.
For example, if you provide the value 4 x ONEHOUR
to
this method, then it returns either 0400hrs on the current day (if that
time is still in the future), or 0400hrs tomorrow.
millisSinceMidnight
- Ticks since midnight.
IllegalArgumentException
- Thrown if the specified date value is
less than 0.public static Calendar getDate(int millisSinceMidnight)
milisSinceMidnight
- Ticks since midnight.
IllegalArgumentException
- Thrown if the specified date value is
less than 0.public static void formatElapsedTime(long time, StringBuffer sb, boolean reset)
This method prints out a formatted version of a duration into a
buffer, providing a string like this d:hh:mm:ss
if the
duration involves at least one day, h:mm:ss
if the duration
involves at least one hour, and m:ss
otherwise.
Single letters in the formats mean that the value is printed with no
leading zeros; double letters in the formats mean that the value includes
leading zeros padding single digit values. For example, one day, four
hours, fifteen minutes, and zero seconds would appear like this:
1:04:15:00
.
time
- Length of duration in seconds.sb
- Buffer to hold the formatted duration.reset
- If true, this method truncates the buffer before appending
the formatted results; if false, this method appends the results
preserving the buffer's current contents.
IllegalArgumentException
- Thrown if the specified date value is
less than 0.public static int[] getCalendarFields(Calendar cal, int[] fields)
Invoke this method to extract the various date/time fields from a calendar object (year, month, day, hour, minute, second, tick) as integers, and store the results in an integer array.
cal
- Source calendar object.fields
- Array to fill with the field values. If this is null, then
this method allocates (and returns) a new array; if this array is too
small, then this method resizes the array as needed.
public static void setCalendarFields(Calendar cal, int[] fields)
Invoke this method to set the various date/time fields in a calendar object (year, month, day, hour, minute, second, tick) with integers.
cal
- Calendar object to modify.fields
- Field values; if you provide a null array, or one with less
than seven elements, this method does nothing.public static boolean isSameDate(long date1, long date2, TimeZone tz1, TimeZone tz2)
date1
- The first date in milliseconds.date2
- The second date in milliseconds.tz1
- The Timezone for date1.tz2
- The Timezone for date2 - null if tz1 is to be used as the default Timezone for both dates.
public static boolean isSameDate(long date1, long date2)
date1
- The first date in milliseconds.date2
- The second date in milliseconds.
public static boolean isSameDate(long date1, long date2, TimeZone tz1, TimeZone tz2, Calendar cal)
date1
- The first date in milliseconds.date2
- The second date in milliseconds.tz1
- The Timezone for date1 - if null the default timezone is used.tz2
- The Timezone for date2 - null if tz1 is to be used as the default Timezone for both dates.cal
- Calendar object to perform date calculations, if none is provide, one is created.
public static long copyCalendar(Calendar source, Calendar destination)
source
- The source calendardestination
- The destination calendar
public static void zeroCalendarTime(Calendar calendar)
source
- Calendar to reset to 12ampublic static boolean isLeapYear(int year)
Note: Unlike GregorianCalendar, this does not handle dates
prior to the Gregorian cutover year, which is 1582. If
year
values less than 1582, including negative values, are
passed in to this method, it will still return corresponding
boolean
return values without throwing an exception, but
the results are invalid.
year
- the year to check. It should be greater than or equal to 1582.
year
is a leap year.public static int getWeekOfYear(Calendar calendar, long date, int firstDayofWeek)
calendar
- Calendar object to use for calculation - doesn't need to be initalized to the date.date
- GMT time of date you wish to obtain the week number for.firstDayofWeek
- One of Calendar.DAY_OF_WEEK
, a day representing the first day of the week.
For example Calendar.MONDAY
. At the present time, the
value of this argument is ignored. This method uses Calendar.MONDAY as the
first day of the week regardless of the value specified for the firstDayofWeek parameter.
NullPointerException
- Thrown if calendar is null.public static int getNumberOfDaysInMonth(int month, int year)
month
- The month to check. A valid month
is between 0 and 11.year
- The year the month is in.
month
has been
specified, the return value will be -1.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright 1999-2011 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Java is a trademark of Oracle America Inc. in the US and other countries.
Legal