Package org.sm.smtools.util
Class TimeStamp
java.lang.Object
org.sm.smtools.util.TimeStamp
- All Implemented Interfaces:
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/08/2022
- Author:
- Sven Maerivoet
-
Constructor Summary
ConstructorDescriptionConstructs 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.Constructs aTimeStamp
object corresponding to the specified Unix time (number of milliseconds since the epoch) using a specified time zone.Constructs aTimeStamp
object corresponding to the specified string representation.Constructs aTimeStamp
object as a copy of anotherTimeStamp
object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Sets thisTimeStamp
to 00:00:00.000.int
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, 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, ZoneId timeZoneID) Converts thisTimeStamp
object to a Unix time (number of milliseconds since the epoch) using a specified date and time zone.static void
convertToUTC
(String dateTimeStampStr, DateStamp dateStamp, TimeStamp timeStamp) Converts the given date- and time description into UTC-zoned date- and timestamps.
The description has the format of YYYY-MM-DDTHH:MM:SS+|-HH:MMstatic void
convertToUTC
(DateStamp dateStamp, TimeStamp timeStamp, String zoneStr) Converts the given date- and timestamps to UTC, taking a specified time zone into account.boolean
Defaultequals()
operator.Returns aString
representation of thisTimeStamp
object in the format HH:mm:ss.SSS.Returns aString
representation of thisTimeStamp
object in the format HH:mm:ss.Returns aString
representation of thisTimeStamp
object in the format HH:mm.int
getHour()
Returns thisTimeStamp
's hour of the day [0-23].int
Returns thisTimeStamp
's millisecond [0-999].int
Returns thisTimeStamp
's millisecond-of-day (since 00:00:00.000).int
Returns thisTimeStamp
's minute [0-59].int
Returns thisTimeStamp
's minute-of-day (since 00:00:00.000).Returns aString
representation of thisTimeStamp
object in the format mm:ss.SSS.Returns aString
representation of thisTimeStamp
object in the format mm:ss.int
Returns thisTimeStamp
's second [0-59].int
Returns thisTimeStamp
's second-of-day (since 00:00:00.000).Returns aString
representation of thisTimeStamp
object in the format ss.SSS.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
Sets thisTimeStamp
equal to another one.void
Sets thisTimeStamp
object corresponding to the specified string representation.void
Sets thisTimeStamp
object corresponding to the specified string representation.void
setToHMSMs
(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.toString()
Default overloadedtoString()
method.
-
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:
-
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
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:
-
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:
-
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:
-
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
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:
-
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:
-
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:
-
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:
-
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:
-
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:
-
getSString
Returns aString
representation of thisTimeStamp
object in the format ss.- Returns:
- a
String
representation of thisTimeStamp
object in the format ss - See Also:
-
convertFromUnixTime
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)
-
convertToUTC
Converts the given date- and timestamps to UTC, taking a specified time zone into account.- Parameters:
dateStamp
- the datestamp to use and converttimeStamp
- the timestamp to use and convertzoneStr
- the time zone
-
convertToUTC
Converts the given date- and time description into UTC-zoned date- and timestamps.
The description has the format of YYYY-MM-DDTHH:MM:SS+|-HH:MM- Parameters:
dateTimeStampStr
- the date- and time description to use (YYYY-MM-DDTHH:MM:SS+HH:MM)dateStamp
- the datestamp to store the result intotimeStamp
- the timestamp to store the result into
-
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 interfaceComparable<TimeStamp>
-
toString
Default overloadedtoString()
method. -
equals
Defaultequals()
operator. -
hashCode
public int hashCode()
-