FileDocCategorySizeDatePackage
Time.javaAPI DocAndroid 1.5 API8374Wed May 06 22:41:06 BST 2009java.sql

Time

public class Time extends Date
Java representation of an SQL {@code TIME} value. Provides utilities to format and parse the time's representation as a String in JDBC escape format.
since
Android 1.0

Fields Summary
private static final long
serialVersionUID
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.

deprecated
Please use the constructor {@link #Time(long)}.
param
theHour a value in the range {@code [0,23]}.
param
theMinute a value in the range {@code [0,59]}.
param
theSecond a value in the range {@code [0,59]}.
since
Android 1.0

        super(70, 0, 1, theHour, theMinute, theSecond);
    
public Time(long theTime)
Constructs a {@code Time} object using a supplied time specified in milliseconds.

param
theTime a {@code Time} specified in milliseconds since the Epoch (January 1st 1970, 00:00:00.000).
since
Android 1.0

        super(theTime);
    
Methods Summary
public intgetDate()

deprecated
This method is deprecated and must not be used. An SQL {@code Time} object does not have a {@code Date} component.
return
does not return anything.
throws
IllegalArgumentException if this method is called.
since
Android 1.0

        throw new IllegalArgumentException();
    
public intgetDay()

deprecated
This method is deprecated and must not be used. An SQL {@code Time} object does not have a Day component.
return
does not return anything.
throws
IllegalArgumentException if this method is called.
since
Android 1.0

        throw new IllegalArgumentException();
    
public intgetMonth()

deprecated
This method is deprecated and must not be used. An SQL {@code Time} object does not have a Month component.
return
does not return anything.
throws
IllegalArgumentException if this method is called.
since
Android 1.0

        throw new IllegalArgumentException();
    
public intgetYear()

deprecated
This method is deprecated and must not be used. An SQL {@code Time} object does not have a Year component.
return
does not return anything.
throws
IllegalArgumentException if this method is called.
since
Android 1.0

        throw new IllegalArgumentException();
    
public voidsetDate(int i)

deprecated
This method is deprecated and must not be used. An SQL {@code Time} object does not have a {@code Date} component.
throws
IllegalArgumentException if this method is called.
since
Android 1.0

        throw new IllegalArgumentException();
    
public voidsetMonth(int i)

deprecated
This method is deprecated and must not be used. An SQL {@code Time} object does not have a Month component.
throws
IllegalArgumentException if this method is called.
since
Android 1.0

        throw new IllegalArgumentException();
    
public voidsetTime(long time)
Sets the time for this {@code Time} object to the supplied milliseconds value.

param
time A time value expressed as milliseconds since the Epoch. Negative values are milliseconds before the Epoch. The Epoch is January 1 1970, 00:00:00.000.
since
Android 1.0

        super.setTime(time);
    
public voidsetYear(int i)

deprecated
This method is deprecated and must not be used. An SQL {@code Time} object does not have a Year component.
throws
IllegalArgumentException if this method is called.

        throw new IllegalArgumentException();
    
public java.lang.StringtoString()
Formats the {@code Time} as a String in JDBC escape format: {@code hh:mm:ss}.

return
A String representing the {@code Time} value in JDBC escape format: {@code HH:mm:ss}
since
Android 1.0

        SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); //$NON-NLS-1$
        return dateFormat.format(this);
    
public static java.sql.TimevalueOf(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.

param
timeString A String representing the time value in JDBC escape format: {@code hh:mm:ss}.
return
The {@code Time} object set to a time corresponding to the given time.
throws
IllegalArgumentException if the supplied time string is not in JDBC escape format.
since
Android 1.0

        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);