Package util
Class Time
java.lang.Object
util.Time
Objects of this class supply methods that may be used for telling time and
parsing String representations of time in dd:hh:mm:ss or hh:mm:ss or hh:mm formats
and translating them into seconds formats.The reverse is also possible:i.e translating time in seconds into dd:hh:mm:ss format.
When combined with Timer objects,objects of this class can help in creating timing utilities for software.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTime()
No-argument constructor for creating objects of class Time.sets all the numerical properties of the object to 0Time
(int seconds) Time
(int minutes, int seconds) Time
(int hours, int minutes, int seconds) Time
(long days, int hours, int minutes, int seconds) This constructor creates objects of class Time and determines the values of various properties of the created based on the input time. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
convertSecondsToTime
(long seconds) void
format$ValidateTime
(String time) This method determines the values associated with various properties of objects of this class dependent on the input time.long
getDays()
int
getHours()
int
int
getTime()
boolean
boolean
boolean
boolean
boolean
isSimilarTo
(Time t2) boolean
static void
void
setDays
(long days) void
setHours
(int hours) void
setMinutes
(int minutes) void
setSeconds
(int seconds) void
timeAddition
(Time t1) static String
long
toString()
-
Field Details
-
days
private long days -
hours
private int hours -
minutes
private int minutes -
seconds
private int seconds
-
-
Constructor Details
-
Time
public Time()No-argument constructor for creating objects of class Time.sets all the numerical properties of the object to 0 -
Time
This constructor creates objects of class Time and determines the values of various properties of the created based on the input time.- Parameters:
time
- the time property of the created object
-
Time
public Time(long days, int hours, int minutes, int seconds) - Parameters:
days
- The days attribute.hours
- The hours attribute.minutes
- The minutes attribute.seconds
- The seconds attribute.
-
Time
public Time(int hours, int minutes, int seconds) - Parameters:
hours
- The hours attribute.minutes
- The minutes attribute.seconds
- The seconds attribute.
-
Time
public Time(int minutes, int seconds) - Parameters:
minutes
- The minutes attribute.seconds
- The seconds attribute.
-
Time
public Time(int seconds) - Parameters:
seconds
- The seconds attribute.
-
-
Method Details
-
format$ValidateTime
This method determines the values associated with various properties of objects of this class dependent on the input time. It accomplishes this by parsing and validating the input time, and from there assigns values to various properties of the Time object based on the results of the parsing and validating. The time is entered in the format "dd:hh:mm:ss" or "hh:mm:ss" or hh:mm- Parameters:
time
- the time property of the created object
-
timeDiff
- Parameters:
t1
- The Time object to combine subtractively with this one.- Returns:
- a Time object that represents the absolute difference between both Time objects.
-
timeAddition
- Parameters:
t1
- The Time object to combine additively with this one.- Returns:
- a time object that represents the absolute difference between both Time objects.
-
getTime
- Returns:
- the current value of the time. The returned time is not the current system time.To get the current system time, make a call to method timeGetter()
-
setTime
- Parameters:
time
- the value that we wish to change the time to manipulate to.
-
getDays
public long getDays() -
setDays
public void setDays(long days) -
getHours
public int getHours() -
setHours
public void setHours(int hours) -
getMinutes
public int getMinutes() -
setMinutes
public void setMinutes(int minutes) -
getSeconds
public int getSeconds() -
setSeconds
public void setSeconds(int seconds) -
isAhead
- Parameters:
t2
- The other Time object to compare with this one.- Returns:
- true if this Time object is ahead of the other one.
-
isBehind
- Parameters:
t2
- The other Time object to compare with this one.- Returns:
- true if this Time object is behind the other one.
-
isSimilarTo
- Parameters:
t2
- The other Time object to compare with this one.- Returns:
- true if this Time object represents a time similar to this one.
-
timeToSeconds
public long timeToSeconds()- Returns:
- the seconds format of the input time. e.g 00:01:00:00 becomes 3600
-
timeString
- Returns:
- a String object representing this Time object in dd:hh:mm:ss format.
-
timeGetter
- Returns:
- the system time and writes it in the hh:mm:ss format
-
convertSecondsToTime
- Parameters:
seconds
- the time in seconds.- Returns:
- the time in the dd:hh:mm:ss format.
-
isBehindSystemTime
public boolean isBehindSystemTime() -
isSimilarToSystemTime
public boolean isSimilarToSystemTime() -
isAheadOfSystemTime
public boolean isAheadOfSystemTime() -
toString
-
main
-