---
schema_version: "1"
id: c5323d98b84ab88ddbb06159b721c7e3667b6c6feeebcc71cd2519afb16a311d
title: Time Class
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_methods_system_time.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_time.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: fa7bdc8b103ff285638c455f774ab38b7f67de05bd815899b5cc0abe9b575c54
description: Contains methods for the Time primitive data type.Adds the specified number of hours to a Time.Adds the specified number of milliseconds to a Time.Adds the specified number of minutes to a Time.Adds the specified number of seconds to a Time.Returns the hour component of a Time.Returns the millisecond component of a Time.Returns the minute component of a Time.Constructs a Time from Integer representations of the specified hour, minutes, seconds, and milliseconds. (UTC is assumed.)Returns the second component of a Time.
---
# Time Class

Contains methods for the Time primitive data type.

## Namespace

[System](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_namespace_System.htm "The System namespace provides classes and methods for core Apex functionality.")

## Usage

For more information on time, see [Time Data Type](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexcode.meta/apexcode/langCon_apex_primitives.htm).

## Time Methods

The following are methods for Time.

- **[addHours(additionalHours)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_time.htm#apex_System_Time_addHours)**  
    Adds the specified number of hours to a Time.
- **[addMilliseconds(additionalMilliseconds)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_time.htm#apex_System_Time_addMilliseconds)**  
    Adds the specified number of milliseconds to a Time.
- **[addMinutes(additionalMinutes)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_time.htm#apex_System_Time_addMinutes)**  
    Adds the specified number of minutes to a Time.
- **[addSeconds(additionalSeconds)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_time.htm#apex_System_Time_addSeconds)**  
    Adds the specified number of seconds to a Time.
- **[hour()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_time.htm#apex_System_Time_hour)**  
    Returns the hour component of a Time.
- **[millisecond()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_time.htm#apex_System_Time_millisecond)**  
    Returns the millisecond component of a Time.
- **[minute()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_time.htm#apex_System_Time_minute)**  
    Returns the minute component of a Time.
- **[newInstance(hour, minutes, seconds, milliseconds)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_time.htm#apex_System_Time_newInstance)**  
    Constructs a Time from Integer representations of the specified hour, minutes, seconds, and milliseconds. (UTC is assumed.)
- **[second()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_time.htm#apex_System_Time_second)**  
    Returns the second component of a Time.

### addHours(additionalHours)

Adds the specified number of hours to a Time.

#### Signature

public Time addHours(Integer additionalHours)

#### Parameters

- **additionalHours**: Type: [Integer](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_integer.htm#apex_methods_system_integer "Contains methods for the Integer primitive data type.")

#### Return Value

Type: [Time](#apex_methods_system_time "Contains methods for the Time primitive data type.")

#### Example

Time myTime = Time.newInstance(1, 2, 3, 4);
Time expected = Time.newInstance(4, 2, 3, 4);
Assert.areEqual(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](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_integer.htm#apex_methods_system_integer "Contains methods for the Integer primitive data type.")

#### Return Value

Type: [Time](#apex_methods_system_time "Contains methods for the Time primitive data type.")

#### Example

Time myTime = Time.newInstance(1, 2, 3, 0);
Time expected = Time.newInstance(1, 2, 4, 400);
Assert.areEqual(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](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_integer.htm#apex_methods_system_integer "Contains methods for the Integer primitive data type.")

#### Return Value

Type: [Time](#apex_methods_system_time "Contains methods for the Time primitive data type.")

#### Example

Time myTime = Time.newInstance(18, 30, 2, 20);
Integer myMinutes = myTime.minute();
myMinutes = myMinutes + 5;
Assert.areEqual(35, myMinutes);

### addSeconds(additionalSeconds)

Adds the specified number of seconds to a Time.

#### Signature

public Time addSeconds(Integer additionalSeconds)

#### Parameters

- **additionalSeconds**: Type: [Integer](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_integer.htm#apex_methods_system_integer "Contains methods for the Integer primitive data type.")

#### Return Value

Type: [Time](#apex_methods_system_time "Contains methods for the Time primitive data type.")

#### Example

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

### hour()

Returns the hour component of a Time.

#### Signature

public Integer hour()

#### Return Value

Type: [Integer](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_integer.htm#apex_methods_system_integer "Contains methods for the Integer primitive data type.")

#### Example

Time myTime = Time.newInstance(18, 30, 2, 20);
myTime = myTime.addHours(2);
Integer myHour = myTime.hour();
Assert.areEqual(20, myHour);

### millisecond()

Returns the millisecond component of a Time.

#### Signature

public Integer millisecond()

#### Return Value

Type: [Integer](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_integer.htm#apex_methods_system_integer "Contains methods for the Integer primitive data type.")

#### Example

Time myTime = Time.newInstance(3, 14, 15, 926);
Assert.areEqual(926, myTime.millisecond());

### minute()

Returns the minute component of a Time.

#### Signature

public Integer minute()

#### Return Value

Type: [Integer](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_integer.htm#apex_methods_system_integer "Contains methods for the Integer primitive data type.")

#### Example

Time myTime = Time.newInstance(3, 14, 15, 926);
Assert.areEqual(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](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_integer.htm#apex_methods_system_integer "Contains methods for the Integer primitive data type.")
- **minutes**: Type: [Integer](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_integer.htm#apex_methods_system_integer "Contains methods for the Integer primitive data type.")
- **seconds**: Type: [Integer](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_integer.htm#apex_methods_system_integer "Contains methods for the Integer primitive data type.")
- **milliseconds**: Type: [Integer](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_integer.htm#apex_methods_system_integer "Contains methods for the Integer primitive data type.")

#### Return Value

Type: [Time](#apex_methods_system_time "Contains methods for the Time primitive data type.")

#### Example

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

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

### second()

Returns the second component of a Time.

#### Signature

public Integer second()

#### Return Value

Type: [Integer](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_integer.htm#apex_methods_system_integer "Contains methods for the Integer primitive data type.")

#### Example

Time myTime = Time.newInstance(3, 14, 15, 926);
Assert.areEqual(15, myTime.second());