Package software.amazon.awscdk
Class Duration
java.lang.Object
software.amazon.jsii.JsiiObject
software.amazon.awscdk.Duration
- All Implemented Interfaces:
software.amazon.jsii.JsiiSerializable
@Generated(value="jsii-pacmak/1.119.0 (build 1634eac)",
date="2025-11-20T23:37:13.151Z")
@Stability(Stable)
public class Duration
extends software.amazon.jsii.JsiiObject
Represents a length of time.
The amount can be specified either as a literal value (e.g: 10) which
cannot be negative, or as an unresolved number token.
When the amount is passed as a token, unit conversion is not possible.
Example:
import software.amazon.awscdk.services.lambda.*;
Function fn;
FunctionUrl fnUrl = fn.addFunctionUrl(FunctionUrlOptions.builder().authType(FunctionUrlAuthType.NONE).build());
Distribution.Builder.create(this, "Distribution")
.defaultBehavior(BehaviorOptions.builder()
.origin(FunctionUrlOrigin.Builder.create(fnUrl)
.readTimeout(Duration.seconds(30))
.responseCompletionTimeout(Duration.seconds(90))
.keepaliveTimeout(Duration.seconds(45))
.build())
.build())
.build();
-
Nested Class Summary
Nested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationMode -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DurationCreate a Duration representing an amount of days.Returns stringified number of duration.static DurationCreate a Duration representing an amount of hours.Checks if duration is a token or a resolvable object.static DurationCreate a Duration representing an amount of milliseconds.Substract two Durations together.static DurationCreate a Duration representing an amount of minutes.static DurationParse a period formatted according to the ISO 8601 standard.Add two Durations together.static DurationCreate a Duration representing an amount of seconds.toDays()Return the total number of days in this Duration.toDays(TimeConversionOptions opts) Return the total number of days in this Duration.toHours()Return the total number of hours in this Duration.toHours(TimeConversionOptions opts) Return the total number of hours in this Duration.Turn this duration into a human-readable string.Return an ISO 8601 representation of this period.Return the total number of milliseconds in this Duration.Return the total number of milliseconds in this Duration.Return the total number of minutes in this Duration.Return the total number of minutes in this Duration.Return the total number of seconds in this Duration.Return the total number of seconds in this Duration.toString()Returns a string representation of thisDuration.Returns unit of the duration.Methods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSetMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
Constructor Details
-
Duration
protected Duration(software.amazon.jsii.JsiiObjectRef objRef) -
Duration
protected Duration(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
-
-
Method Details
-
days
Create a Duration representing an amount of days.- Parameters:
amount- the amount of Days theDurationwill represent. This parameter is required.- Returns:
- a new
DurationrepresentingamountDays.
-
hours
Create a Duration representing an amount of hours.- Parameters:
amount- the amount of Hours theDurationwill represent. This parameter is required.- Returns:
- a new
DurationrepresentingamountHours.
-
millis
Create a Duration representing an amount of milliseconds.- Parameters:
amount- the amount of Milliseconds theDurationwill represent. This parameter is required.- Returns:
- a new
Durationrepresentingamountms.
-
minutes
Create a Duration representing an amount of minutes.- Parameters:
amount- the amount of Minutes theDurationwill represent. This parameter is required.- Returns:
- a new
DurationrepresentingamountMinutes.
-
parse
Parse a period formatted according to the ISO 8601 standard.Days are the largest ISO duration supported, i.e., weeks, months, and years are not supported.
Example:
// This represents 1 day, 2 hours, 3 minutes, 4 seconds, and 567 milliseconds. "P1DT2H3M4.567S";
- Parameters:
duration- an ISO-formatted duration to be parsed. This parameter is required.- Returns:
- the parsed
Duration. - See Also:
-
seconds
Create a Duration representing an amount of seconds.- Parameters:
amount- the amount of Seconds theDurationwill represent. This parameter is required.- Returns:
- a new
DurationrepresentingamountSeconds.
-
formatTokenToNumber
Returns stringified number of duration. -
isUnresolved
Checks if duration is a token or a resolvable object. -
minus
Substract two Durations together.- Parameters:
rhs- This parameter is required.
-
plus
Add two Durations together.- Parameters:
rhs- This parameter is required.
-
toDays
Return the total number of days in this Duration.- Parameters:
opts-- Returns:
- the value of this
Durationexpressed in Days.
-
toDays
Return the total number of days in this Duration.- Returns:
- the value of this
Durationexpressed in Days.
-
toHours
Return the total number of hours in this Duration.- Parameters:
opts-- Returns:
- the value of this
Durationexpressed in Hours.
-
toHours
Return the total number of hours in this Duration.- Returns:
- the value of this
Durationexpressed in Hours.
-
toHumanString
Turn this duration into a human-readable string. -
toIsoString
Return an ISO 8601 representation of this period.- Returns:
- a string starting with 'P' describing the period
- See Also:
-
toMilliseconds
Return the total number of milliseconds in this Duration.- Parameters:
opts-- Returns:
- the value of this
Durationexpressed in Milliseconds.
-
toMilliseconds
Return the total number of milliseconds in this Duration.- Returns:
- the value of this
Durationexpressed in Milliseconds.
-
toMinutes
Return the total number of minutes in this Duration.- Parameters:
opts-- Returns:
- the value of this
Durationexpressed in Minutes.
-
toMinutes
Return the total number of minutes in this Duration.- Returns:
- the value of this
Durationexpressed in Minutes.
-
toSeconds
Return the total number of seconds in this Duration.- Parameters:
opts-- Returns:
- the value of this
Durationexpressed in Seconds.
-
toSeconds
Return the total number of seconds in this Duration.- Returns:
- the value of this
Durationexpressed in Seconds.
-
toString
Returns a string representation of thisDuration.This is is never the right function to use when you want to use the
Durationobject in a template. UsetoSeconds(),toMinutes(),toDays(), etc. instead. -
unitLabel
Returns unit of the duration.
-