public class Time
extends java.lang.Object
Note: To use the proper timezone should set
TimeZone.setDefault(TimeZone.getTimeZone(timeZoneStr));
before
this class is initialized. Otherwise the SimpleDateFormat objects will
wrongly use the system default timezone.
Modifier and Type | Field and Description |
---|---|
static long |
DAY_IN_MSECS |
static int |
DAY_IN_SECS |
static int |
HOUR_IN_MINS |
static long |
HOUR_IN_MSECS |
static int |
HOUR_IN_SECS |
static int |
MIN_IN_MSECS |
static int |
MIN_IN_SECS |
static int |
MIN_PER_HOUR |
static long |
MS_PER_DAY |
static long |
MS_PER_HOUR |
static int |
MS_PER_MIN |
static int |
MS_PER_SEC |
static long |
MS_PER_WEEK |
static long |
MS_PER_YEAR |
static long |
MSEC_IN_NSECS |
static long |
NSEC_PER_MSEC |
static int |
SEC_IN_MSECS |
static int |
SEC_PER_DAY |
static int |
SEC_PER_HOUR |
static int |
SEC_PER_MIN |
static long |
WEEK_IN_MSECS |
static long |
YEAR_IN_MSECS |
Constructor and Description |
---|
Time(DbConfig dbConfig)
Methods
|
Time(java.lang.String timeZoneStr)
Creates a Time object for the specified timezone.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
dateStr(java.util.Date epochTime)
Returns date in format "MM-dd-yyyy"
|
static java.lang.String |
dateStr(long epochTime)
Returns date in format "MM-dd-yyyy"
|
static java.lang.String |
dateTimeStr(java.util.Date epochTime)
Returns epochTime as a string in the format MM-dd-yyyy HH:mm:ss z
|
static java.lang.String |
dateTimeStr(long epochTime)
Returns epochTime as a string in the format MM-dd-yyyy HH:mm:ss z
|
static java.lang.String |
dateTimeStrMsec(java.util.Date epochTime)
Returns epochTime as a string, including msec, in the
format MM-dd-yyyy HH:mm:ss.SSS z
|
static java.lang.String |
dateTimeStrMsec(long epochTime)
Returns epochTime as a string in the format MM-dd-yyyy HH:mm:ss.SSS z
|
java.lang.String |
dateTimeStrMsecForTimezone(long epochTime)
Returns epochTime as a string in the format MM-dd-yyyy HH:mm:ss.SSS z
but does so for the Timezone specified by this Time object.
|
static java.lang.String |
elapsedTimeStr(long msec)
Returns the elapsed time in msec as a string.
|
int |
getDayOfYear(java.util.Date epochDate)
Returns day of year.
|
long |
getEpochTime(int secondsIntoDay,
java.util.Date referenceDate)
Converts secondsIntoDay into an epoch time.
|
long |
getEpochTime(int secondsIntoDay,
long referenceTime)
Converts secondsIntoDay into an epoch time.
|
int |
getMsecsIntoDay(java.util.Date epochTime)
Converts the epoch time into number of msec into the day.
|
long |
getMsecsIntoDay(java.util.Date epochTime,
long referenceTimeIntoDayMsecs)
Returns time of day in msecs.
|
int |
getSecondsIntoDay(java.util.Date epochDate)
Converts the epoch time into number of seconds into the day.
|
int |
getSecondsIntoDay(long epochTime)
Converts the epoch time into number of seconds into the day.
|
static long |
getStartOfDay(java.util.Date date)
Returns the epoch time of the start of the current day for the default
timezone.
|
static long |
getStartOfDay(java.util.Date date,
java.util.TimeZone tz)
Returns the epoch time of the start of the day for the date and timezone
specified.
|
static int |
getTimeDifference(int time1SecsIntoDay,
int time2SecsIntoDay)
Returns the absolute value of the difference between the two times.
|
static java.lang.String |
httpDate(long epochTime)
For when sending date as part of http request.
|
static void |
main(java.lang.String[] args) |
static java.lang.String |
minutesStr(long msec)
Outputs time in minutes with a single digit past the decimal point
|
static java.util.Date |
parse(java.lang.String datetimeStr)
Parses the datetimeStr and returns a Date object.
|
static java.util.Date |
parseDate(java.lang.String dateStr)
Parses the dateStr and returns a Date object.
|
static int |
parseTimeOfDay(java.lang.String timeStr)
Parses a time such as HH:MM:SS or HH:MM into seconds into the day.
|
java.util.Date |
parseUsingTimezone(java.lang.String dateStr)
Parses the dateStr into a Date using the timezone for this Time object.
|
static java.lang.String |
secondsStr(long msec)
Outputs time in seconds with a single digit past the decimal point
|
static void |
sleep(long msec)
Simply calls Thread.sleep() but catches the InterruptedException
so that the calling function doesn't need to.
|
static java.lang.String |
timeOfDayAmPmStr(java.lang.Integer secInDay)
Converts seconds in day to a string HH:MM AM/PM.
|
static java.lang.String |
timeOfDayAmPmStr(long secInDay)
Converts seconds in day to a string HH:MM AM/PM.
|
static java.lang.String |
timeOfDayShortStr(java.lang.Integer secInDay)
Converts seconds in day to a string HH:MM.
|
static java.lang.String |
timeOfDayShortStr(long secInDay)
Converts seconds in day to a string HH:MM.
|
static java.lang.String |
timeOfDayStr(java.lang.Integer secInDay)
Converts seconds in day to a string HH:MM:SS.
|
static java.lang.String |
timeOfDayStr(long secInDay)
Converts seconds in day to a string HH:MM:SS.
|
static java.lang.String |
timeStr(java.util.Date epochTime)
Returns just the time string in format "HH:mm:ss z"
|
static java.lang.String |
timeStr(long epochTime)
Returns just the time string in format "HH:mm:ss z"
|
java.lang.String |
timeStrForTimezone(long epochTime) |
static java.lang.String |
timeStrMsec(java.util.Date epochTime)
Returns just the time string.
|
static java.lang.String |
timeStrMsec(long epochTime)
Returns just the time string.
|
static java.lang.String |
timeStrMsecNoTimeZone(java.util.Date epochTime)
Returns just the time string.
|
static java.lang.String |
timeStrMsecNoTimeZone(long epochTime)
Returns just the time string.
|
static java.lang.String |
timeStrNoTimeZone(java.util.Date epochTime)
Returns just the time string in format "HH:mm:ss"
|
static java.lang.String |
timeStrNoTimeZone(long epochTime)
Returns just the time string in format "HH:mm:ss"
|
public static final int MS_PER_SEC
public static final int SEC_IN_MSECS
public static final int MS_PER_MIN
public static final int MIN_IN_MSECS
public static final long MS_PER_HOUR
public static final long HOUR_IN_MSECS
public static final long MS_PER_DAY
public static final long DAY_IN_MSECS
public static final long MS_PER_WEEK
public static final long WEEK_IN_MSECS
public static final long MS_PER_YEAR
public static final long YEAR_IN_MSECS
public static final int SEC_PER_MIN
public static final int MIN_IN_SECS
public static final int SEC_PER_HOUR
public static final int HOUR_IN_SECS
public static final int SEC_PER_DAY
public static final int DAY_IN_SECS
public static final int MIN_PER_HOUR
public static final int HOUR_IN_MINS
public static final long NSEC_PER_MSEC
public static final long MSEC_IN_NSECS
public Time(DbConfig dbConfig)
public Time(java.lang.String timeZoneStr)
timeZoneStr
- Such as "America/Los_Angeles" . List of time zones can be found
at http://en.wikipedia.org/wiki/List_of_tz_database_time_zones .
If null then local timezone is usedpublic int getSecondsIntoDay(long epochTime)
epochTime
- public int getSecondsIntoDay(java.util.Date epochDate)
epochTime
- public int getDayOfYear(java.util.Date epochDate)
epochDate
- public int getMsecsIntoDay(java.util.Date epochTime)
epochTime
- public static long getStartOfDay(java.util.Date date, java.util.TimeZone tz)
date
- the time that the start of the day is needed fortz
- the timezonepublic static long getStartOfDay(java.util.Date date)
date
- the time that the start of the day is needed forpublic long getEpochTime(int secondsIntoDay, java.util.Date referenceDate)
secondsIntoDay
- To be converted into epoch timereferenceDate
- The approximate epoch time so that can handle times before and
after midnight.public long getEpochTime(int secondsIntoDay, long referenceTime)
secondsIntoDay
- To be converted into epoch timereferenceTime
- The approximate epoch time so that can handle times before and
after midnight.public long getMsecsIntoDay(java.util.Date epochTime, long referenceTimeIntoDayMsecs)
epochTime
- referenceTimeIntoDayMsecs
- public java.util.Date parseUsingTimezone(java.lang.String dateStr) throws java.text.ParseException
dateStr
- java.text.ParseException
public static java.util.Date parse(java.lang.String datetimeStr) throws java.text.ParseException
datetimeStr
- java.text.ParseException
public static java.util.Date parseDate(java.lang.String dateStr) throws java.text.ParseException
dateStr
- java.text.ParseException
public static int parseTimeOfDay(java.lang.String timeStr)
public static java.lang.String timeOfDayStr(long secInDay)
secInDay
- public static java.lang.String timeOfDayStr(java.lang.Integer secInDay)
secInDay
- public static java.lang.String timeOfDayShortStr(long secInDay)
secInDay
- public static java.lang.String timeOfDayShortStr(java.lang.Integer secInDay)
secInDay
- public static java.lang.String timeOfDayAmPmStr(long secInDay)
secInDay
- public static java.lang.String timeOfDayAmPmStr(java.lang.Integer secInDay)
secInDay
- Can be nullpublic static java.lang.String minutesStr(long msec)
msec
- public static java.lang.String secondsStr(long msec)
msec
- public static java.lang.String elapsedTimeStr(long msec)
msec
- public static java.lang.String dateStr(long epochTime)
epochTime
- public static java.lang.String dateStr(java.util.Date epochTime)
epochTime
- public static java.lang.String dateTimeStr(long epochTime)
epochTime
- public static java.lang.String dateTimeStr(java.util.Date epochTime)
epochTime
- public static java.lang.String dateTimeStrMsec(long epochTime)
epochTime
- public java.lang.String dateTimeStrMsecForTimezone(long epochTime)
epochTime
- public java.lang.String timeStrForTimezone(long epochTime)
public static java.lang.String dateTimeStrMsec(java.util.Date epochTime)
epochTime
- public static java.lang.String timeStr(long epochTime)
epochTime
- public static java.lang.String timeStr(java.util.Date epochTime)
epochTime
- public static java.lang.String timeStrNoTimeZone(long epochTime)
epochTime
- public static java.lang.String timeStrNoTimeZone(java.util.Date epochTime)
epochTime
- public static java.lang.String timeStrMsec(java.util.Date epochTime)
epochTime
- public static java.lang.String timeStrMsec(long epochTime)
epochTime
- public static java.lang.String timeStrMsecNoTimeZone(long epochTime)
epochTime
- public static java.lang.String timeStrMsecNoTimeZone(java.util.Date epochTime)
epochTime
- public static java.lang.String httpDate(long epochTime)
epochTime
- public static int getTimeDifference(int time1SecsIntoDay, int time2SecsIntoDay)
time1SecsIntoDay
- time2SecsIntoDay
- public static void sleep(long msec)
msec
- public static void main(java.lang.String[] args)