Time.add

Overview | Methods | Fields | This Package | All Packages

Time.add

Creates a new Time object that represents the number of time units (100 nanoseconds) after the time that this Time object represents. 

Syntax

public Time add( long interval )

Parameters

interval

An integer value that represents the number of time units (100 nanoseconds) to add to the current time.

Return Value

Returns a Time object that represents the new time.

Remarks

Time objects cannot be altered. Use the add method to create a new Time object whose date and time is based on the current Time object but incremented by the number of time units specified in interval.

The following example illustrates how to use the add 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.add(Time.UNITS_PER_HOUR * 2);
	//Output the time
	System.out.println("The time two hours from now is: " + twoHoursLater.toString());
}

See Also   Time.UNITS_PER_HOUR