Package org.sm.smtools.util
Class TimeStamp
java.lang.Object
org.sm.smtools.util.TimeStamp
- All Implemented Interfaces:
java.lang.Comparable<TimeStamp>
public final class TimeStamp extends java.lang.Object implements java.lang.Comparable<TimeStamp>
The
TimeStamp
class acts as a container for time stamps.
A time stamp is defined by its hour, minute, second and millisecond.
Note that this class cannot be subclassed!
- Version:
- 03/04/2020
- Author:
- Sven Maerivoet
-
Constructor Summary
Constructors Constructor Description TimeStamp()
Constructs aTimeStamp
object corresponding to the current system time.TimeStamp(int hour, int minute, int second)
Constructs aTimeStamp
object corresponding to the specified values.TimeStamp(int hour, int minute, int second, int millisecond)
Constructs aTimeStamp
object corresponding to the specified values.TimeStamp(long unixMilliseconds)
Constructs aTimeStamp
object corresponding to the specified Unix time (number of milliseconds since the epoch) using the user's local time zone.TimeStamp(long unixMilliseconds, java.time.ZoneId timeZoneID)
Constructs aTimeStamp
object corresponding to the specified Unix time (number of milliseconds since the epoch) using a specified time zone.TimeStamp(java.lang.String timeString)
Constructs aTimeStamp
object corresponding to the specified string representation.TimeStamp(TimeStamp timeStamp)
Constructs aTimeStamp
object as a copy of anotherTimeStamp
object. -
Method Summary
Modifier and Type Method Description void
clear()
Sets thisTimeStamp
to 00:00:00.000.int
compareTo(TimeStamp otherTimeStamp)
The overloadedComparable
interface.void
convertFromUnixTime(long unixMilliseconds)
Converts thisTimeStamp
object from a Unix time (number of milliseconds since the epoch) using the user's local time zone.void
convertFromUnixTime(long unixMilliseconds, java.time.ZoneId timeZoneID)
Converts thisTimeStamp
object from a Unix time (number of milliseconds since the epoch) using a specified time zone.long
convertToUnixTime(DateStamp date)
Converts thisTimeStamp
object to a Unix time (number of milliseconds since the epoch) using the user's date and local time zone.long
convertToUnixTime(DateStamp date, java.time.ZoneId timeZoneID)
Converts thisTimeStamp
object to a Unix time (number of milliseconds since the epoch) using a specified date and time zone.boolean
equals(java.lang.Object object)
Defaultequals()
operator.java.lang.String
getHMSMsString()
Returns aString
representation of thisTimeStamp
object in the format HH:mm:ss.SSS.java.lang.String
getHMSString()
Returns aString
representation of thisTimeStamp
object in the format HH:mm:ss.java.lang.String
getHMString()
Returns aString
representation of thisTimeStamp
object in the format HH:mm.int
getHour()
Returns thisTimeStamp
's hour of the day [0-23].int
getMillisecond()
Returns thisTimeStamp
's millisecond [0-999].int
getMillisecondOfDay()
Returns thisTimeStamp
's millisecond-of-day (since 00:00:00.000).int
getMinute()
Returns thisTimeStamp
's minute [0-59].int
getMinuteOfDay()
Returns thisTimeStamp
's minute-of-day (since 00:00:00.000).java.lang.String
getMSMsString()
Returns aString
representation of thisTimeStamp
object in the format mm:ss.SSS.java.lang.String
getMSString()
Returns aString
representation of thisTimeStamp
object in the format mm:ss.int
getSecond()
Returns thisTimeStamp
's second [0-59].int
getSecondOfDay()
Returns thisTimeStamp
's second-of-day (since 00:00:00.000).java.lang.String
getSMsString()
Returns aString
representation of thisTimeStamp
object in the format ss.SSS.java.lang.String
getSString()
Returns aString
representation of thisTimeStamp
object in the format ss.int
hashCode()
void
set(int hour, int minute, int second, int millisecond)
Sets thisTimeStamp
to the specified values.void
set(TimeStamp timeStamp)
Sets thisTimeStamp
equal to another one.void
setToHM(java.lang.String timeString)
Sets thisTimeStamp
object corresponding to the specified string representation.void
setToHMS(java.lang.String timeString)
Sets thisTimeStamp
object corresponding to the specified string representation.void
setToHMSMs(java.lang.String timeString)
Sets thisTimeStamp
object corresponding to the specified string representation.void
setToMillisecondOfDay(long millisecond)
Sets thisTimeStamp
based on a cumulative millisecond representation (since 00:00:00.000).void
setToNow()
Sets thisTimeStamp
to the current system time.java.lang.String
toString()
Default overloadedtoString()
method.Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
-
Constructor Details
-
TimeStamp
public TimeStamp()Constructs aTimeStamp
object corresponding to the current system time. -
TimeStamp
public TimeStamp(int hour, int minute, int second)Constructs aTimeStamp
object corresponding to the specified values.The millisecond is set to zero.
- Parameters:
hour
- the hour componentminute
- the minute componentsecond
- the second component
-
TimeStamp
public TimeStamp(int hour, int minute, int second, int millisecond)Constructs aTimeStamp
object corresponding to the specified values.- Parameters:
hour
- the hour componentminute
- the minute componentsecond
- the second componentmillisecond
- the millisecond component
-
TimeStamp
Constructs aTimeStamp
object corresponding to the specified string representation.The string has to have the following specific format: HH:mm:ss, e.g., 12:45:16
- Parameters:
timeString
- the string representation of the time stamp (in the format HH:mm:ss)- Throws:
DateTimeFormatException
- if an error occurred during conversion- See Also:
SimpleDateFormat
-
TimeStamp
public TimeStamp(long unixMilliseconds)Constructs aTimeStamp
object corresponding to the specified Unix time (number of milliseconds since the epoch) using the user's local time zone. The Unix time typically looks like, e.g., 1563319245000L.- Parameters:
unixMilliseconds
- the Unix time (number of milliseconds since the epoch)
-
TimeStamp
public TimeStamp(long unixMilliseconds, java.time.ZoneId timeZoneID)Constructs aTimeStamp
object corresponding to the specified Unix time (number of milliseconds since the epoch) using a specified time zone. The Unix time typically looks like, e.g., 1563319245000L.- Parameters:
unixMilliseconds
- the Unix time (number of milliseconds since the epoch)timeZoneID
- the ID of the time zone
-
TimeStamp
Constructs aTimeStamp
object as a copy of anotherTimeStamp
object.This is the copy constructor.
- Parameters:
timeStamp
- theTimeStamp
object to deep copy
-
-
Method Details
-
clear
public void clear()Sets thisTimeStamp
to 00:00:00.000. -
set
public void set(int hour, int minute, int second, int millisecond)Sets thisTimeStamp
to the specified values.- Parameters:
hour
- the hour componentminute
- the minute componentsecond
- the second componentmillisecond
- the millisecond component
-
set
Sets thisTimeStamp
equal to another one.- Parameters:
timeStamp
- theTimeStamp
to copy
-
setToMillisecondOfDay
public void setToMillisecondOfDay(long millisecond)Sets thisTimeStamp
based on a cumulative millisecond representation (since 00:00:00.000).- Parameters:
millisecond
- the number of milliseconds (since 00:00:00.000) to convert to aTimeStamp
object
-
setToHM
Sets thisTimeStamp
object corresponding to the specified string representation.The string has to have the following specific format: HH:mm, e.g., 10:15
- Parameters:
timeString
- the string representation of the time stamp (in the format HH:mm)- Throws:
DateTimeFormatException
- if an error occurred during conversion- See Also:
SimpleDateFormat
-
setToHMS
Sets thisTimeStamp
object corresponding to the specified string representation.The string has to have the following specific format: HH:mm:ss, e.g., 12:45:16 or 8:32:48
- Parameters:
timeString
- the string representation of the time stamp (in the format HH:mm:ss)- Throws:
DateTimeFormatException
- if an error occurred during conversion- See Also:
SimpleDateFormat
-
setToHMSMs
Sets thisTimeStamp
object corresponding to the specified string representation.The string has to have the following specific format: HH:mm:ss.mls, e.g., 12:45:16.002
- Parameters:
timeString
- the string representation of the time stamp (in the format HH:mm:ss.SSS)- Throws:
DateTimeFormatException
- if an error occurred during conversion- See Also:
SimpleDateFormat
-
setToNow
public void setToNow()Sets thisTimeStamp
to the current system time. -
getHour
public int getHour()Returns thisTimeStamp
's hour of the day [0-23].- Returns:
- the hour
-
getMinute
public int getMinute()Returns thisTimeStamp
's minute [0-59].- Returns:
- the minute
-
getSecond
public int getSecond()Returns thisTimeStamp
's second [0-59].- Returns:
- the second
-
getMillisecond
public int getMillisecond()Returns thisTimeStamp
's millisecond [0-999].- Returns:
- the millisecond
-
getMinuteOfDay
public int getMinuteOfDay()Returns thisTimeStamp
's minute-of-day (since 00:00:00.000).- Returns:
- the number of minutes (since 00:00:00:000) corresponding to this
TimeStamp
object
-
getSecondOfDay
public int getSecondOfDay()Returns thisTimeStamp
's second-of-day (since 00:00:00.000).- Returns:
- the number of seconds (since 00:00:00:000) corresponding to this
TimeStamp
object
-
getMillisecondOfDay
public int getMillisecondOfDay()Returns thisTimeStamp
's millisecond-of-day (since 00:00:00.000).- Returns:
- the number of milliseconds (since 00:00:00:000) corresponding to this
TimeStamp
object
-
getHMSMsString
public java.lang.String getHMSMsString()Returns aString
representation of thisTimeStamp
object in the format HH:mm:ss.SSS.- Returns:
- a
String
representation of thisTimeStamp
object in the format HH:mm:ss.SSS - See Also:
SimpleDateFormat
-
getHMSString
public java.lang.String getHMSString()Returns aString
representation of thisTimeStamp
object in the format HH:mm:ss.- Returns:
- a
String
representation of thisTimeStamp
object in the format HH:mm:ss - See Also:
SimpleDateFormat
-
getHMString
public java.lang.String getHMString()Returns aString
representation of thisTimeStamp
object in the format HH:mm.- Returns:
- a
String
representation of thisTimeStamp
object in the format HH:mm - See Also:
SimpleDateFormat
-
getMSString
public java.lang.String getMSString()Returns aString
representation of thisTimeStamp
object in the format mm:ss.- Returns:
- a
String
representation of thisTimeStamp
object in the format mm:ss - See Also:
SimpleDateFormat
-
getMSMsString
public java.lang.String getMSMsString()Returns aString
representation of thisTimeStamp
object in the format mm:ss.SSS.- Returns:
- a
String
representation of thisTimeStamp
object in the format mm:ss.SSS - See Also:
SimpleDateFormat
-
getSMsString
public java.lang.String getSMsString()Returns aString
representation of thisTimeStamp
object in the format ss.SSS.- Returns:
- a
String
representation of thisTimeStamp
object in the format ss.SSS - See Also:
SimpleDateFormat
-
getSString
public java.lang.String getSString()Returns aString
representation of thisTimeStamp
object in the format ss.- Returns:
- a
String
representation of thisTimeStamp
object in the format ss - See Also:
SimpleDateFormat
-
convertFromUnixTime
public void convertFromUnixTime(long unixMilliseconds, java.time.ZoneId timeZoneID)Converts thisTimeStamp
object from a Unix time (number of milliseconds since the epoch) using a specified time zone. The Unix time typically looks like, e.g., 1563319245000L.- Parameters:
unixMilliseconds
- the Unix time (number of milliseconds since the epoch)timeZoneID
- the ID of the time zone
-
convertFromUnixTime
public void convertFromUnixTime(long unixMilliseconds)Converts thisTimeStamp
object from a Unix time (number of milliseconds since the epoch) using the user's local time zone. The Unix time typically looks like, e.g., 1563319245000L.- Parameters:
unixMilliseconds
- the Unix time (number of milliseconds since the epoch)
-
convertToUnixTime
Converts thisTimeStamp
object to a Unix time (number of milliseconds since the epoch) using a specified date and time zone. The Unix time typically looks like, e.g., 1563319245000L.- Parameters:
date
- the date at which the timestamp occurstimeZoneID
- the ID of the time zone- Returns:
- the Unix time (number of milliseconds since the epoch)
-
convertToUnixTime
Converts thisTimeStamp
object to a Unix time (number of milliseconds since the epoch) using the user's date and local time zone. The Unix time typically looks like, e.g., 1563319245000L.- Parameters:
date
- the date at which the timestamp occurs- Returns:
- the Unix time (number of milliseconds since the epoch)
-
compareTo
The overloadedComparable
interface.- Specified by:
compareTo
in interfacejava.lang.Comparable<TimeStamp>
-
toString
public java.lang.String toString()Default overloadedtoString()
method.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a
String
representation of thisTimeStamp
object in the format HH:mm:ss.SSS - See Also:
SimpleDateFormat
-
equals
public boolean equals(java.lang.Object object)Defaultequals()
operator.- Overrides:
equals
in classjava.lang.Object
- Returns:
true
if both objects denote the same time stamp,false
otherwise
-
hashCode
public int hashCode()- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- the object's unique hashcode
-