public class Time extends DataObject implements LocaleFormatted, IDate, ITime, Comparable, Value
As of Eve vesion 1.14 you should use eve.sys.SimpleDateFormat to format and parse Time values.
A Time object is displayed as a string in a manner specified by the "format" string. If this value is null it will be formatted as by the "defaultFormat" string.
The format string uses the convention as the java.util.SimpleDateFormat with some specifiers left out. What is included are:
Symbol Meaning Presentation Example ------ ------- ------------ ------- y year (Number) 1996 M month in year (Text & Number) July & 07 d day in month (Number) 10 h hour in am/pm (1~12) (Number) 12 H hour in day (0~23) (Number) 0 m minute in hour (Number) 30 s second in minute (Number) 55 S millisecond (Number) 978 E day in week (Text) Tuesday a am/pm marker (Text) PM z GMT TimeZone (Text & Number) GMT+00:00 Z RFC 822 Time Zones (Number) -0400 ' escape for text
Time also implements Textable and getText()/setText() encodes the object in a numeric form that is independant of the format used for toString()/fromString().
Modifier and Type | Field and Description |
---|---|
String |
_fields |
int |
day
The day in the range of 1 to the last day in the month.
|
static int |
DAY |
int |
dayOfWeek
The day of the week in the range 1 to 7, with 1 being Monday and 7 being Sunday
|
static String |
defaultFormat
The default format to use if one is not specified.
|
String |
format
The date format to use for I/O with this Time object.
|
int |
hour
The hour in the range of 0 to 23.
|
static int |
HOUR |
static long |
invalidTime
Used for user interfaces to mark an invalid/unentered time.
|
int |
millis
Milliseconds in the range of 0 to 999.
|
int |
minute
The minute in the range of 0 to 59.
|
static int |
MINUTE |
int |
month
The month in the range of 1 to 12.
|
static int |
MONTH |
static int |
NO_TIME_ZONE_IN_ENCODED_TIME
This is a possible return value from encodedTimeToTimeZoneOffset() indicating
that the encoded time did not have any TimeZone offset stored within it.
|
int |
second
The second in the range of 0 to 59.
|
static int |
SECOND |
int |
year
The year as its full set of digits (year 2010 is 2010).
|
static int |
YEAR |
Constructor and Description |
---|
Time()
Constructs a time object set to the current date and time.
|
Time(int day,
int month,
int year) |
Modifier and Type | Method and Description |
---|---|
boolean |
after(Time other) |
boolean |
before(Time other) |
static int |
compareEncodedTimes(long one,
long two,
boolean ignoreDate,
boolean ignoreTime)
Compare two encoded times.
|
int |
compareTo(Object other)
Compare this object with another.
|
void |
copyFrom(Object other)
Copy all appropriate data from another object.
|
boolean |
dateIsValid() |
static int |
encodedTimeToTimeZoneOffset(long encodedTime) |
static boolean |
encodedTimeToTimeZoneOffset(long encodedTime,
SimpleTimeZone simpleTimeZone)
From an encoded time value (created by getEncodedTime()) extract the
saved TimeZone offset from UTC and place it in the specified SimpleTimeZone.
|
void |
format(LocaleFormat locale,
CharArray dest) |
String |
format(String dateFormat) |
String |
format(String format,
Locale locale)
Format this Time object with a particular format and particular locale.
|
String |
format(TimeZone tz,
String format,
Locale locale) |
Time |
fromCalendar(Calendar source) |
void |
fromString(char[] src,
int offset,
int length) |
void |
fromString(String source) |
void |
fromString(String source,
Locale locale) |
static boolean |
fromString(String source,
Time t,
String format,
Locale locale) |
PlainDate |
getDate(PlainDate dest) |
String |
getDefaultFormat() |
long |
getEncodedTime()
This converts to a 64-bit encoded values saving the year, month, day, hours, min, sec, millisec in
a platform independent manner.
|
long |
getEncodedTime(TimeZone forZone)
This converts to a 64-bit encoded values saving the year, month, day, hours, min, sec, millisec in
a platform independent manner.
|
String |
getFormat() |
String |
getText() |
long |
getTime()
This method returns the UTC time in milliseconds using the default
TimeZone - which means that the value this returns for a given
set of Y/M/D/h/m/s values will be different depending on the default
TimeZone.
|
PlainTime |
getTime(PlainTime dest) |
int |
getTimeZoneUTCOffset(TimeZone tz)
Determine the offset in milliseconds of the Time specified in this time Object from UTC
time at a particular TimeZone.
|
long |
getUTCMillis(TimeZone tz)
What is the UTC millisecond value given this Time's Y/M/D/h/m/s values at the
specified TimeZone.
|
int |
hashCode()
Returns a hashCode for the object.
|
static int |
indexOfDayInWeek(int dayOfWeek,
Locale locale)
This returns the index of the day in the week.
|
boolean |
isInvalidTime()
See if the long millisecond value of this Time is the one marked for invalid time
(equal to the invalidTime field).
|
static boolean |
isLeapYear(int year)
Returns if the specified year is a leap year.
|
boolean |
isValid() |
static long |
localTimeToUTC(long localTime)
Deprecated.
- use Time.localToUTC(Time dest,TimeZone tz) instead.
|
Time |
localToUTC(Time dest,
TimeZone tz)
Determine what the UTC time was at a particular Time (given by the
Y/M/D/h/m/s values in this Time Object)
at a particular TimeZone.
|
void |
makeDateInvalid() |
void |
makeTimeInvalid() |
static int |
numberOfDays(int month,
int year)
Find the number of days in a month on a particular year.
|
void |
parse(LocaleFormat locale,
char[] data,
int offset,
int length) |
void |
parse(String dateValue) |
void |
parse(String dateValue,
String dateFormat) |
Time |
roundTo(int roundTo)
Rounds this time down.
|
void |
setDate(int day,
int month,
int year) |
boolean |
setDayOfYear(Time other)
Set the date fields only in this Time object to be the same as
the other Time object.
|
Time |
setEncodedTime(long from)
This converts from a 64-bit encoded values saving the year, month, day, hours, min, sec, millisec in
a platform independent manner.
|
static boolean |
setEncodedTime(long encodedTime,
Calendar destination)
From an encoded time produced by getEncodedTime() set a Calendar with
the encoded time and TimeZone set to the TimeZone offset stored in the
encoded time.
|
Time |
setFormat(String format) |
void |
setLocalTime()
Set the local time on the computer to the specified time.
|
void |
setText(String text) |
void |
setTime(int hour,
int minute,
int second,
int millis) |
Time |
setTime(long time)
This methods sets the Y/M/D/h/m/s values of this Time value based on the
UTC time given and the default TimeZone.
|
boolean |
setTimeOfDay(Time other)
Set the Time of day fields only in this Time object to be the same as
the other Time object.
|
Time |
setToCurrentTime()
Set the time to be the current local time.
|
Time |
setUTCMillis(TimeZone tz,
long utcMillis)
Set the Time Y/M/D/h/m/s to be the time that it was at the specified TimeZone
given the specified UTC millisecond value.
|
boolean |
timeIsValid() |
Calendar |
toCalendar(Calendar destination) |
String |
toString()
Return a String representation of this object.
|
CharArray |
toString(CharArray dest) |
String |
toString(Locale locale) |
static String |
toString(Time t,
String format,
Locale locale)
Format a Time object with a particular format and particular locale.
|
static CharArray |
toString(Time t,
String format,
Locale locale,
CharArray dest) |
static CharArray |
toString(Time t,
TimeZone tz,
String format,
Locale locale,
CharArray dest) |
Time |
update()
Update values like dayOfWeek from the year, month, day and time values.
|
static long |
UTCTimeToLocal(long utcTime)
Deprecated.
- use Time.UTCToLocal(Time dest,TimeZone tz) instead.
|
Time |
UTCToLocal(Time dest,
TimeZone tz)
Determine what the local time at a current TimeZone was at a particular UTC time(given by the
year,month,day,hours,minutes,seconds,millis values in this Time Object)
at a particular TimeZone.
|
_getFieldType, _getSetField, cache, copied, equals, getCopy, getDeclaredField, getDeclaredFieldValue, getMyFieldList, getNew
public int year
public int month
public int day
public int hour
public int minute
public int second
public int millis
public int dayOfWeek
public String format
public static String defaultFormat
public static long invalidTime
public String _fields
public static final int SECOND
public static final int MINUTE
public static final int HOUR
public static final int DAY
public static final int MONTH
public static final int YEAR
public static final int NO_TIME_ZONE_IN_ENCODED_TIME
public Time()
public Time(int day, int month, int year)
public void copyFrom(Object other)
DataUnit
copyFrom
in interface DataUnit
copyFrom
in class DataObject
public long getTime()
public Time setTime(long time)
time
- the UTC time in milliseconds.public boolean isInvalidTime()
public Time update()
public boolean isValid()
public String getFormat()
public String getDefaultFormat()
public void parse(String dateValue, String dateFormat) throws IllegalArgumentException
IllegalArgumentException
public void parse(String dateValue) throws IllegalArgumentException
IllegalArgumentException
public void fromString(String source)
fromString
in interface Stringable
public Time roundTo(int roundTo)
roundTo
- should be SECOND, MINUTE, HOUR, ...public int compareTo(Object other)
Comparable
compareTo
in interface Comparable
compareTo
in class DataObject
public boolean before(Time other)
public boolean after(Time other)
public String toString()
Object
toString
in interface Stringable
toString
in class Object
public String format(String format, Locale locale)
format
- the format String.locale
- the Locale to use.public static String toString(Time t, String format, Locale locale)
t
- the Time Object to format.format
- the format String.locale
- the Locale to use.public static CharArray toString(Time t, TimeZone tz, String format, Locale locale, CharArray dest)
public static int indexOfDayInWeek(int dayOfWeek, Locale locale)
public long getEncodedTime(TimeZone forZone)
forZone
- - the TimeZone to encode. The value of the offset from UTC
time is calculated (to a 15 minute resolution) and encoded along with
the time fields. Note that this can only be in the range +/-15 hours and 45 minutes.public long getEncodedTime()
Note that this version will save NO TimeZone information.
public Time setEncodedTime(long from)
public static boolean encodedTimeToTimeZoneOffset(long encodedTime, SimpleTimeZone simpleTimeZone)
The supplied SimpleTimeZone will have its Daylight Savings Time Savings value set to zero because the information in the encodedTime only specifies the raw offset at that time but does not indicate if the TimeZone it represents had daylight savings time or not. Then the raw offset is set to the offset saved in the encoded time.
simpleTimeZone
- the SimpleTimeZone to have its offset set.public static boolean setEncodedTime(long encodedTime, Calendar destination)
encodedTime
- the encoded time.destination
- a non-null destination Calendar.public static int encodedTimeToTimeZoneOffset(long encodedTime)
encodedTime
- the encoded time produced by getEncodedTime().public static int compareEncodedTimes(long one, long two, boolean ignoreDate, boolean ignoreTime)
one
- An encoded time from getEncodedTime().two
- An encoded time from getEncodedTime().ignoreDate
- if this is true then the date portion will be ignored.ignoreTime
- if this is true then the time portion will be ignored.public String getText()
public void setText(String text)
public int hashCode()
Object
public boolean setTimeOfDay(Time other)
other
- the other Time to take the time values from.public boolean setDayOfYear(Time other)
other
- the other Time to take the date values from.public Time setToCurrentTime()
public static int numberOfDays(int month, int year)
public static boolean isLeapYear(int year)
public long getUTCMillis(TimeZone tz)
tz
- the TimeZone.public Time setUTCMillis(TimeZone tz, long utcMillis)
tz
- the TimeZone. If null the default TimeZone is used.utcMillis
- the UTC millisecond value.public Time localToUTC(Time dest, TimeZone tz)
dest
- an optional destination Time to hold the year,month,day,hours,minutes,seconds and millis
of the UTC that coincided with the time given by this Time Object.tz
- the TimeZone at which this Time object was current - or null
for the default TimeZone.public Time UTCToLocal(Time dest, TimeZone tz)
dest
- an optional destination Time to hold the year,month,day,hours,minutes,seconds and millis
of the UTC that co-incided with the time given by this Time Object.tz
- the TimeZone at which this Time object was current - or null
for the default TimeZone.public int getTimeZoneUTCOffset(TimeZone tz)
tz
- the TimeZone.public static long localTimeToUTC(long localTime)
public static long UTCTimeToLocal(long utcTime)
public void setLocalTime() throws IllegalAccessException, IllegalArgumentException
IllegalAccessException
- if the current process does not have permission to
do this.IllegalArgumentException
- if the time in this Time Object is not considered
a valid time to set the Time to.public CharArray toString(CharArray dest)
toString
in interface Stringable
public void fromString(char[] src, int offset, int length)
fromString
in interface Stringable
public void setTime(int hour, int minute, int second, int millis)
public boolean dateIsValid()
dateIsValid
in interface IDate
public void makeDateInvalid()
makeDateInvalid
in interface IDate
public void makeTimeInvalid()
makeTimeInvalid
in interface ITime
public boolean timeIsValid()
timeIsValid
in interface ITime
public void format(LocaleFormat locale, CharArray dest)
format
in interface LocaleFormatted
public void parse(LocaleFormat locale, char[] data, int offset, int length) throws ParseException
parse
in interface LocaleFormatted
ParseException