Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Time Class
Namespace
Usage
For more information on time, see Time Data Type.
Time Methods
The following are methods for Time.
addHours(additionalHours)
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)
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)
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)
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()
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()
Signature
public Integer millisecond()
Return Value
Type: Integer
Example
1Time myTime = Time.newInstance(3, 14, 15, 926);
2System.assertEquals(926, myTime.millisecond());minute()
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)
Signature
public static Time newInstance(Integer hour, Integer minutes, Integer seconds, Integer milliseconds)
Parameters
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()
Signature
public Integer second()
Return Value
Type: Integer
Example
1Time myTime = Time.newInstance(3, 14, 15, 926);
2System.assertEquals(15, myTime.second());