Class TimeUtil
A collection of static utility methods for manipulation of time measured in milliseconds since Unix epoch.
Porting a Java class com.devexperts.util.TimeUtil
.
public static class TimeUtil
- Inheritance
-
TimeUtil
- Inherited Members
Fields
Day
Number of milliseconds in a day.
public const long Day = 86400000
Field Value
Hour
Number of milliseconds in an hour.
public const long Hour = 3600000
Field Value
Minute
Number of milliseconds in a minute.
public const long Minute = 60000
Field Value
Second
Number of milliseconds in a second.
public const long Second = 1000
Field Value
Methods
GetMillisFromTime(long)
Returns correct number of milliseconds with proper handling negative values. Idea is that number of milliseconds shall be within [0..999] interval so that the following equation always holds:
GetSecondsFromTime(timeMillis) * 1000L + GetMillisFromTime(timeMillis) == timeMillis
as long the time in seconds fits into int. GetSecondsFromTime(long)
public static int GetMillisFromTime(long timeMillis)
Parameters
timeMillis
longThe time measured in milliseconds since Unix epoch.
Returns
- int
The number of milliseconds.
GetSecondsFromTime(long)
Returns correct number of seconds with proper handling negative values and overflows. Idea is that number of milliseconds shall be within [0..999] interval so that the following equation always holds:
GetSecondsFromTime(timeMillis) * 1000L + GetMillisFromTime(timeMillis) == timeMillis
as long the time in seconds fits into int. GetMillisFromTime(long)
public static int GetSecondsFromTime(long timeMillis)
Parameters
timeMillis
longThe time measured in milliseconds since Unix epoch.
Returns
- int
The number of seconds.