|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavabook.Clock
This class supports some basic clock functions such as reading the current time, getting today's date, and stop watch function. This class also supports a convenient function to pause the program execution.
This class is provided as freeware. You are free to use as provided or modify to your heart's content. But you use it at your own risk. No implied or explicit warranty is given.
Field Summary | |
static int |
LONG_FORMAT
Designates the long format for date |
static int |
SHORT_FORMAT
Designates the short format for date |
static int |
TIME_12HR_FORMAT
Designates the 12-hr format for time |
static int |
TIME_24HR_FORMAT
Designates the 24-hr format for time |
Constructor Summary | |
Clock()
Default constructor. |
Method Summary | |
java.lang.String |
getCurrentDate()
Returns the current (today's) date in the mm/dd/yyyy format. |
java.lang.String |
getCurrentDate(int format)
Returns the current (today's) date in short or long format. |
java.lang.String |
getCurrentTime()
Returns the current time in the 12-hr format. |
java.lang.String |
getCurrentTime(int format)
Returns the current time in 24-hr or 12-hr format. |
double |
getElapsedTime()
Returns the elapsed time of the stop watch function. |
double |
getTotalElapsedTime()
Returns the total elapsed time of the stop watch function. |
void |
pause(double duration)
Pauses the program execution. |
void |
reset()
Resets the stop watch to its initial state. |
void |
start()
Starts the clock's stop watch. |
void |
stop()
Stops the clock's stop watch. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int LONG_FORMAT
public static final int SHORT_FORMAT
public static final int TIME_12HR_FORMAT
public static final int TIME_24HR_FORMAT
Constructor Detail |
public Clock()
Method Detail |
public java.lang.String getCurrentDate()
public java.lang.String getCurrentDate(int format)
format
- specify LONG_FORMAT or SHORT_FORMAT
public java.lang.String getCurrentTime()
public java.lang.String getCurrentTime(int format)
format
- specify TIME_12HR_FORMAT or TIME_24HR_FORMAT
public double getElapsedTime()
public double getTotalElapsedTime()
public void pause(double duration)
duration
- the amount to time (in seconds) to pause the program executionpublic void reset()
public void start()
public void stop()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |