Class TimeT
- All Implemented Interfaces:
Serializable
,Comparable
- Author:
- Doug Dodge
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final double
static final double
static final int
Number of seconds in a daystatic final int
Number of seconds in an hourstatic final int
Number of seconds in a minute -
Constructor Summary
ConstructorDescriptionTimeT()
Default Constructor for the TimeT object.TimeT
(double epochtime) Constructor for the TimeT object that takes a double epoch time.TimeT
(int year, int month, int day, int hour, int minute, double second) Constructor for the TimeT object that takes numerical values for year, month, day, hour, minute, and second.TimeT
(int year, int jday, int hour, int min, int sec, int msec) Constructor for the TimeT object that takes all int values for year, day of year, hour, minute, second, and millisecond.TimeT
(int year, int month, int day, int hour, int minute, int sec, int msec) Constructor for the TimeT object that takes all int values for year, month, day, hour, minute, second, and millisecond.TimeT
(long epochInMilliseconds) Constructor for a TimeT that takes a long holding the number of milliseconds relative to 1970/01/01 00:00:00.0Constructor for the TimeT object that takes a String representation of the time and a String specifying the format for the time string.Copy constructor for the TimeT object -
Method Summary
Modifier and TypeMethodDescriptionadd
(double v) Produce a new TimeT object whose Epoch time is the sum of the Epoch times in this object and the input double (interpreted as an Epoch time).Produce a new TimeT object whose Epoch time is the sum of the Epoch times in this object and the input object.int
long
Return the Epoch time expressed in milliseconds relative to 1970/01/01 00:00:00.0static int
EpochToJdate
(double time) static String
EpochToString
(double time) static String
EpochToString2
(double time, String format) boolean
Return true if the input Object is a TimeT object and if its millisecond and microsecond fields match those from this Object.boolean
Return true if this epoch time is greater than or equal to the input epoch timeint
int
getDate()
static Date
getDateFrom
(String timeString, String formatString) int
Gets the dayOfMonth attribute of the TimeT objectint
Gets the dayOfYear attribute of the TimeT objectdouble
Gets the epochTime ( time in seconds relative to 1970/01/01 00:00:00.0 )of the TimeT objectdouble
int
getHour()
Gets the hour attribute of the TimeT objectint
getJdate()
Gets the jdate attribute of the TimeT object.int
getJDay()
static int
getMaxDaysOfMonth
(int year, int month) Gets the MaxDaysOfMonth attribute of the TimeT objectlong
returns the epochtime in millisecondsint
Gets the minute attribute of the TimeT objectint
getMonth()
Gets the month attribute of the TimeT objectstatic int
getMonthFromString
(String month) int
getMsec()
int
getSec()
double
Gets the second attribute of the TimeT objectstatic TimeT
getTimeFromDateString
(String dateStr) int
getWeek()
int
getYear()
Gets the year attribute of the TimeT objectboolean
Return true if this epoch time is greater than the input epoch timeint
hashCode()
Returns a hash code based on the microseconds and milliseconds fields of the object.boolean
static boolean
isLeapYear
(int year) Determines if the given year is a leap year.static double
jdateToEpoch
(int jdate) static TimeT
jdateToTimeT
(int jdate) boolean
Return true if this epoch time is less than or equal to the input epoch timeboolean
Return true if this epoch time is less than the input epoch timevoid
print
(PrintStream ps) Use the object's toString method to print into a PrintStreamRound the epoch time to the nearest whole day.Round the epoch time to the nearest whole hour.Round the epoch time to the nearest whole minute.Round the epoch time to the nearest whole second.subtract
(double v) Subtract the input TimeT from this TimeT and return the resulting epoch time as a double.double
Subtract the input TimeT from this TimeT and return the resulting epoch time as a double.static long
toMilliseconds
(double seconds) toString()
Return a String representation of the time based on the default Time format String.Return a String representation of the time based on the supplied string template
-
Field Details
-
SECPERMIN
public static final int SECPERMINNumber of seconds in a minute- See Also:
-
SECPERDAY
public static final int SECPERDAYNumber of seconds in a day- See Also:
-
SECPERHOUR
public static final int SECPERHOURNumber of seconds in an hour- See Also:
-
AVG_DAYS_PER_YEAR
public static final double AVG_DAYS_PER_YEAR- See Also:
-
MAX_EPOCH_TIME
public static final double MAX_EPOCH_TIME- See Also:
-
-
Constructor Details
-
TimeT
public TimeT()Default Constructor for the TimeT object. Gets the system time and converts it to GMT time. That time is used to initialize the TimeT object. -
TimeT
public TimeT(int year, int month, int day, int hour, int minute, double second) Constructor for the TimeT object that takes numerical values for year, month, day, hour, minute, and second.- Parameters:
year
- The year (including century, e.g. 1999)month
- Month of the year January = 1, ... December = 12day
- Day of the month 0 LT day LTEQ daysInMonth( year, month );hour
- An integer value from 0 - 23. Note: If hour is outside those bounds, day, month, and year may be changed to force hour into its bounds.minute
- An integer value from 0 - 59. As with hour, out of range values may force a cascading change of other fields.second
- A double value from 0 - 59.999999
-
TimeT
public TimeT(int year, int month, int day, int hour, int minute, int sec, int msec) Constructor for the TimeT object that takes all int values for year, month, day, hour, minute, second, and millisecond.- Parameters:
year
- The year (including century, e.g. 1999)month
- Month of the year January = 1, ... December = 12day
- Day of the month 0 LT day LTEQ daysInMonth( year, month );hour
- An int val ue from 0 - 23. Note: If hour is outside those bounds, day, month, and year may be changed to force hour into its bounds. @param minute An int value from 0 - 59. As with hour, out of range values may force a cascading change of other fields. @param sec An int value from 0 - 59 @param msec A n int value from 0 to 999
-
TimeT
public TimeT(int year, int jday, int hour, int min, int sec, int msec) Constructor for the TimeT object that takes all int values for year, day of year, hour, minute, second, and millisecond.- Parameters:
year
- The year (including century, e.g. 1999)jday
- day of the year ( 1 - 365 or 366 in leap years)hour
- An int value from 0 - 23. Note: If hour is outside those bounds, day, month, and year may be changed to force hour into its bounds.sec
- An int value from 0 - 59msec
- An int value from 0 to 999min
- Description of the Parameter
-
TimeT
public TimeT(double epochtime) Constructor for the TimeT object that takes a double epoch time.- Parameters:
epochtime
- A double value holding the number of seconds relative to 1970/01/01 00:00:00.0
-
TimeT
public TimeT(long epochInMilliseconds) Constructor for a TimeT that takes a long holding the number of milliseconds relative to 1970/01/01 00:00:00.0- Parameters:
epochInMilliseconds
- the number of milliseconds relative to 1970/01/01 00:00:00.0
-
TimeT
Constructor for the TimeT object that takes a String representation of the time and a String specifying the format for the time string.- Parameters:
timeString
- A String representation of the time, e.g. "1994/02/24 06:17:12.234"formatString
-A format String that specifies how to interpret the time String. The format String must follow the rules of SimpleDateFormat. You must not attempt to specify seconds to more than 1 millisecond of precision. Doing so, will result in an incorrect parse. For example a time String of "12.12345" with a format String of "ss.SSSSS" will result in seconds interpreted as 12.345.
The following pattern letters are defined (all other characters from 'A' to 'Z' and from 'a' to 'z' are reserved):
Letter Date or Time Component Presentation Examples G Era designator Text AD y Year Year 1996; 96 M Month in year Month July; Jul; 07 w Week in year Number 27 W Week in month Number 2 D Day in year Number 189 d Day in month Number 10 F Day of week in month Number 2 E Day in week Text Tuesday; Tue a Am/pm marker Text PM H Hour in day (0-23) Number 0 k Hour in day (1-24) Number 24 K Hour in am/pm (0-11) Number 0 h Hour in am/pm (1-12) Number 12 m Minute in hour Number 30 s Second in minute Number 55 S Millisecond Number 978 z Time zone General time zone Pacific Standard Time; PST; GMT-08:00 Z Time zone RFC 822 time zone -0800
Pattern letters are usually repeated, as their number determines the exact presentation: Text: For formatting, if the number of pattern letters is 4 or more, the full form is used; otherwise a short or abbreviated- Throws:
ParseException
- This exception is thrown if the format String is incompatible with the time String or uses invalid format codes.- See Also:
-
TimeT
-
TimeT
-
TimeT
Copy constructor for the TimeT object- Parameters:
other
-
-
-
Method Details
-
add
Produce a new TimeT object whose Epoch time is the sum of the Epoch times in this object and the input object.- Parameters:
other
-- Returns:
- A TimeT object whose Epoch time is the sum of the two input Epoch times.
-
subtract
Subtract the input TimeT from this TimeT and return the resulting epoch time as a double.- Parameters:
other
-- Returns:
- Resulting epoch time as a double
-
subtractD
Subtract the input TimeT from this TimeT and return the resulting epoch time as a double.- Parameters:
other
-- Returns:
- Resulting epoch time as a double
-
add
Produce a new TimeT object whose Epoch time is the sum of the Epoch times in this object and the input double (interpreted as an Epoch time).- Parameters:
v
- Some number of seconds.- Returns:
- A TimeT object whose Epoch time is the sum of the two input Epoch times.
-
subtract
- Parameters:
v
- Time in seconds- Returns:
-
epochAsLong
public long epochAsLong()Return the Epoch time expressed in milliseconds relative to 1970/01/01 00:00:00.0- Returns:
- The milliseconds relative to 1970/01/01 00:00:00.0
-
getEpochTime
public double getEpochTime()Gets the epochTime ( time in seconds relative to 1970/01/01 00:00:00.0 )of the TimeT object- Returns:
- The epochTime value
-
getYear
public int getYear()Gets the year attribute of the TimeT object- Returns:
- An int value representing the year ( including the century )
-
getDayOfYear
public int getDayOfYear()Gets the dayOfYear attribute of the TimeT object- Returns:
- The dayOfYear value ( 1-365 or 1-366 in a leap year )
-
getJDay
public int getJDay()- Returns:
- The day of the year
-
getJdate
public int getJdate()Gets the jdate attribute of the TimeT object. Jdate is the year * 1000 + the DayOfYear, e.g. for the 23rd day of the year 1995 the Jdate is 1995023.- Returns:
- The jdate value
-
getMonth
public int getMonth()Gets the month attribute of the TimeT object- Returns:
- The month value (1 - 12)
-
getDayOfMonth
public int getDayOfMonth()Gets the dayOfMonth attribute of the TimeT object- Returns:
- The dayOfMonth value ( 1 - DaysInMonth( year, month )
-
getHour
public int getHour()Gets the hour attribute of the TimeT object- Returns:
- The hour value ( 0 - 23 )
-
getMinute
public int getMinute()Gets the minute attribute of the TimeT object- Returns:
- The minute value ( 0 - 59 )
-
getSecond
public double getSecond()Gets the second attribute of the TimeT object- Returns:
- The second value ( 0 - 59.999999 )
-
getCalendarSecond
public int getCalendarSecond() -
getCalendarMilliSecond
public int getCalendarMilliSecond() -
getSec
public int getSec()- Returns:
- The integer seconds
-
getMsec
public int getMsec()- Returns:
- Fractional seconds times 1000
-
getMilliseconds
public long getMilliseconds()returns the epochtime in milliseconds- Returns:
- the epoch time in millliseconds
-
roundToSec
Round the epoch time to the nearest whole second.- Returns:
-
roundToMin
Round the epoch time to the nearest whole minute.- Returns:
-
roundToHour
Round the epoch time to the nearest whole hour.- Returns:
-
roundToDay
Round the epoch time to the nearest whole day.- Returns:
-
lt
Return true if this epoch time is less than the input epoch time- Parameters:
T
- A TimeT object- Returns:
- boolean (true if this epoch time is less than the input epoch time, false otherwise)
-
gt
Return true if this epoch time is greater than the input epoch time- Parameters:
T
- A TimeT object- Returns:
- boolean (true if this epoch time is greater than the input epoch time, false otherwise)
-
le
Return true if this epoch time is less than or equal to the input epoch time- Parameters:
T
- A TimeT object- Returns:
- boolean (true if this epoch time is less than or equal to the input epoch time, false otherwise)
-
ge
Return true if this epoch time is greater than or equal to the input epoch time- Parameters:
T
- A TimeT object- Returns:
- boolean (true if this epoch time is greater than or equal to the input epoch time, false otherwise)
-
print
Use the object's toString method to print into a PrintStream- Parameters:
ps
- The input PrintStream
-
getDate
-
toString
Return a String representation of the time based on the supplied string template- Parameters:
format
- A SimpleDateFormat format String. Note: currently TimeString cannot display seconds to a precision better than 1 millisecond, so do not attempt to use more than 3 'S' specifiers. Using more than 3 will cause the fractional seconds value to be zero-padded on the left. For example, if the seconds value is 23.1234 and you use a format specifier that includes 'ss.SSSS', the corresponding part of the output string will be '23.0123'.- Returns:
- A String representation of the time.
- See Also:
-
toString
Return a String representation of the time based on the default Time format String. -
equals
Return true if the input Object is a TimeT object and if its millisecond and microsecond fields match those from this Object. Note that equals does not compare the format field, so two TimeT objects can compare true even when their default formats differ. -
hashCode
public int hashCode()Returns a hash code based on the microseconds and milliseconds fields of the object. -
compareTo
- Specified by:
compareTo
in interfaceComparable
-
toMilliseconds
public static long toMilliseconds(double seconds) -
getDateFrom
- Throws:
ParseException
-
getTimeFromDateString
-
getMonthFromString
-
getMaxDaysOfMonth
public static int getMaxDaysOfMonth(int year, int month) Gets the MaxDaysOfMonth attribute of the TimeT object- Parameters:
year
- The year containing the month to process.month
- The month for which days is to be obtained.- Returns:
- The MaxDaysOfMonth value ( )
-
isLeapYear
public static boolean isLeapYear(int year) Determines if the given year is a leap year.- Parameters:
year
- An integer value including the century, e.g. 1999- Returns:
- True if the year is a leap year.
-
EpochToString
-
EpochToString2
-
EpochToJdate
public static int EpochToJdate(double time) -
jdateToEpoch
public static double jdateToEpoch(int jdate) -
jdateToTimeT
-
getFractionalYear
public double getFractionalYear() -
isLeapYear
public boolean isLeapYear() -
getWeek
public int getWeek()
-