Overview | Methods | Fields | This Package | All Packages
Creates a new Time object that represents the number of hours after the time that this Time object represents.
Syntax
public Time addHours( long interval )
Parameters
interval
A long value that represents the number of hours to add to the current time.
Return Value
Returns a Time object representing the new time.
Remarks
Time objects cannot be altered. Use the addHours method to create a new Time object whose time is based on the current Time object but incremented by the number of hours specified in interval.
Example
The following example illustrates how to use the addHours method to create a new Time object that is two hours later in time than a Time object that is initialized to the current time:
public void AddTwoHours()
{
//Create object that is set to current time
Time now = new Time();
//Output the current time
System.out.println("The current time is: " + now.toString());
//Increment the current time by two hours
Time twoHoursLater = now.addHours(2);
//Output the time
System.out.println("The time two hours from now is: " + twoHoursLater.formatShortTime());
}
See Also addMillis, addMinutes, addSeconds, formatShortTime