Newer Version Available

This content describes an older version of this product. View Latest

Time Class

Contains methods for the Time primitive data type.

Namespace

System

Usage

For more information on time, see Primitive Data Types.

Time Methods

The following are methods for Time.

addHours(additionalHours)

Adds the specified number of hours to a Time.

Signature

public Time addHours(Integer additionalHours)

Parameters

additionalHours
Type: Integer

Return Value

Type: Time

Example

1Time myTime = Time.newInstance(1, 2, 3, 4);
2Time expected = Time.newInstance(4, 2, 3, 4);
3System.assertEquals(expected, myTime.addHours(3));

addMilliseconds(additionalMilliseconds)

Adds the specified number of milliseconds to a Time.

Signature

public Time addMilliseconds(Integer additionalMilliseconds)

Parameters

additionalMilliseconds
Type: Integer

Return Value

Type: Time

Example

1Time myTime = Time.newInstance(1, 2, 3, 0);
2Time expected = Time.newInstance(1, 2, 4, 400);
3System.assertEquals(expected, myTime.addMilliseconds(1400));

addMinutes(additionalMinutes)

Adds the specified number of minutes to a Time.

Signature

public Time addMinutes(Integer additionalMinutes)

Parameters

additionalMinutes
Type: Integer

Return Value

Type: Time

Example

1Time myTime = Time.newInstance(18, 30, 2, 20);
2Integer myMinutes = myTime.minute();
3myMinutes = myMinutes + 5;
4System.assertEquals(myMinutes, 35);

addSeconds(additionalSeconds)

Adds the specified number of seconds to a Time.

Signature

public Time addSeconds(Integer additionalSeconds)

Parameters

additionalSeconds
Type: Integer

Return Value

Type: Time

Example

1Time myTime = Time.newInstance(1, 2, 55, 0);
2Time expected = Time.newInstance(1, 3, 5, 0);
3System.assertEquals(expected, myTime.addSeconds(10));

hour()

Returns the hour component of a Time.

Signature

public Integer hour()

Return Value

Type: Integer

Example

1Time myTime = Time.newInstance(18, 30, 2, 20);
2myTime = myTime.addHours(2);
3Integer myHour = myTime.hour();
4System.assertEquals(myHour, 20);

millisecond()

Returns the millisecond component of a Time.

Signature

public Integer millisecond()

Return Value

Type: Integer

Example

1Time myTime = Time.newInstance(3, 14, 15, 926);
2System.assertEquals(926, myTime.millisecond());

minute()

Returns the minute component of a Time.

Signature

public Integer minute()

Return Value

Type: Integer

Example

1Time myTime = Time.newInstance(3, 14, 15, 926);
2System.assertEquals(14, myTime.minute());

newInstance(hour, minutes, seconds, milliseconds)

Constructs a Time from Integer representations of the specified hour, minutes, seconds, and milliseconds. (UTC is assumed.)

Signature

public static Time newInstance(Integer hour, Integer minutes, Integer seconds, Integer milliseconds)

Parameters

hour
Type: Integer
minutes
Type: Integer
seconds
Type: Integer
milliseconds
Type: Integer

Return Value

Type: Time

Example

The following example creates a time of 18:30:2:20 (UTC).

1Time myTime = 
2Time.newInstance(18, 30, 2, 20);

second()

Returns the second component of a Time.

Signature

public Integer second()

Return Value

Type: Integer

Example

1Time myTime = Time.newInstance(3, 14, 15, 926);
2System.assertEquals(15, myTime.second());