|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.marringtons.time.Time
An object for working with the time of day. String formats for time are hours, minutes, seconds and milliseconds all separated my any non-numeric digit. Alternatively they can be fixed at 2, 2, 2 and 3 digits. 10:00:00.000, 10, 10:00, 1000, 100000, 1000000000 and 10:00am all create the equivalent time objects.
Time time = new Time(); // time now time = new Time( "10:00"); // or at a string format of time.
| Field Summary | |
Calendar |
calendar
Calendar structure for the current time |
int |
days
Days for times above 24 hours |
String |
defaultFormat
Set the default format for writing the time as a string. |
int |
hour
Hour of day (0-24) |
boolean |
isInterval
True if time is an interval rather than a time of day |
int |
millisecond
Millisecond of second (0-999) |
int |
milliseconds
Once a time is set this is the number of milliseconds since the last midnight. |
int |
minute
Minute of hour (0-59) |
int |
second
Second of minute (0-59) |
| Constructor Summary | |
Time()
Default constructor sets the time for now - using the local computer rtc. |
|
Time(int days,
int hour,
int minute,
int second,
int millisecond)
Set the time object given a time in components. |
|
Time(long milliseconds)
Set the time given a time in milliseconds. |
|
Time(String time)
Set the time given some user entered time information - flexible format. |
|
| Method Summary | |
int |
compareTo(Object otherTime)
|
boolean |
equals(Object time)
Simple equality given the Epoch time. |
int |
hashCode()
The Epoch time chopped to an integer should make a good hash code. |
static Time |
now()
A convenience method for the default constructor to make code more readable. |
Time |
plus(Time addition)
Calculate the time created by adding 2 times. |
String |
toString()
Convert time to a string using the default format (hh:mm:ss.mmmpp). |
String |
toString(String format)
Convert time to a string using the supplied format (hh:mm:ss.mmm/am/pm/). |
Time |
until(Time to)
Calculate the time between 2 other times over a period of 24 hours or less. |
| Methods inherited from class java.lang.Object |
getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
public int milliseconds
public int days
public int hour
public int minute
public int second
public int millisecond
public boolean isInterval
public Calendar calendar
public String defaultFormat
toString(String)| Constructor Detail |
public Time()
public Time(long milliseconds)
milliseconds - - in day or epoch.
public Time(int days,
int hour,
int minute,
int second,
int millisecond)
days - Can be used for a time a specific number of days away.hour - Hours since midnight.minute - Minutes past the last hour.second - Seconds into the last minute.millisecond - Thousandths of a second past the past second.public Time(String time)
time - String representing the time of day - 12 or 24 hour format.| Method Detail |
public static Time now()
public String toString()
Object.toString()public String toString(String format)
format - Format string
Object.toString()public Time until(Time to)
Time target = new Time( endTimeString); Time toWait = Time.now.until( target);
to - End time
public Time plus(Time addition)
Time endTime = Time.now.add( new Time( timeFromNowString));
addition - Time to add to the time stored in this object.
public boolean equals(Object time)
Object.equals(java.lang.Object)public int hashCode()
Object.hashCode()public int compareTo(Object otherTime)
compareTo in interface ComparableComparable.compareTo(java.lang.Object)
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||