Constructors Summary |
---|
public Time(int theHour, int theMinute, int theSecond)Constructs a {@code Time} object using the supplied values for Hour,
Minute and Second. The Year, Month and
Day elements of the {@code Time} object are set to the date
of the Epoch (January 1, 1970).
Any attempt to access the Year, Month or Day
elements of a {@code Time} object will result in an {@code
IllegalArgumentException}.
The result is undefined if any argument is out of bounds.
super(70, 0, 1, theHour, theMinute, theSecond);
|
public Time(long theTime)Constructs a {@code Time} object using a supplied time specified in
milliseconds.
super(theTime);
|
Methods Summary |
---|
public int | getDate()
throw new IllegalArgumentException();
|
public int | getDay()
throw new IllegalArgumentException();
|
public int | getMonth()
throw new IllegalArgumentException();
|
public int | getYear()
throw new IllegalArgumentException();
|
public void | setDate(int i)
throw new IllegalArgumentException();
|
public void | setMonth(int i)
throw new IllegalArgumentException();
|
public void | setTime(long time)Sets the time for this {@code Time} object to the supplied milliseconds
value.
super.setTime(time);
|
public void | setYear(int i)
throw new IllegalArgumentException();
|
public java.lang.String | toString()Formats the {@code Time} as a String in JDBC escape format: {@code
hh:mm:ss}.
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); //$NON-NLS-1$
return dateFormat.format(this);
|
public static java.sql.Time | valueOf(java.lang.String timeString)Creates a {@code Time} object from a string holding a time represented in
JDBC escape format: {@code hh:mm:ss}.
An exception occurs if the input string does not comply with this format.
if (timeString == null) {
throw new IllegalArgumentException();
}
int firstIndex = timeString.indexOf(':");
int secondIndex = timeString.indexOf(':", firstIndex + 1);
// secondIndex == -1 means none or only one separator '-' has been found.
// The string is separated into three parts by two separator characters,
// if the first or the third part is null string, we should throw
// IllegalArgumentException to follow RI
if (secondIndex == -1|| firstIndex == 0 || secondIndex + 1 == timeString.length()) {
throw new IllegalArgumentException();
}
// parse each part of the string
int hour = Integer.parseInt(timeString.substring(0, firstIndex));
int minute = Integer.parseInt(timeString.substring(firstIndex + 1, secondIndex));
int second = Integer.parseInt(timeString.substring(secondIndex + 1, timeString
.length()));
return new Time(hour, minute, second);
|