Moment.apex

  • Docs
  • Tutorials
Docs Menu
  • Conversion
  • Methods
  • Duration

Duration Guide

Duration

Duration Constructors

Here are the Duration constructors.

ConstructorDescription
Duration(Long, Map)Create a Duration from time in milliseconds and different units of time
Duration(Map)Create a Duration from different units of time
Duration(Integer, String)Create a Duration from some units of time
Duration(Long)Create a Duration from time in milliseconds

Get Time Out of Duration

MethodDescription
getTime()Get time in millis from Duration
getFields()Get units of time from Duration

Display Duration

MethodDescription
humanize()Show the humanized string without suffix
humanize(Boolean)Show the humanized string with or without suffix

Getters

MethodDescription
years()Get years
asYears()Get years
months()Get months
asMonths()Get months
days()Get days
asDays()Get days
hours()Get hours
asHours()Get hours
minutes()Get minutes
asMinutes()Get minutes
seconds()Get seconds
asSeconds()Get seconds
milliseconds()Get milliseconds
asMilliseconds()Get milliseconds
weeks()Get weeks
asWeeks()Get weeks

Generic getters:

MethodDescription
field(String)Get the field
asField(String)Get the field
get(String)Get the field

Operation

Moment.apex also enables operations like adding/subtracting on fields of Duration.

MethodDescription
add(Moment.Duration)Add a duration
add(Long)Add time in milliseconds
add(Integer, String)Add some units of time
add(Map)Add different units of time
subtract(Moment.Duration)Subtract a duration
subtract(Long)Subtract time in milliseconds
subtract(Integer, String)Subtract some units of time
subtract(Map)Subtract different units of time
negate()Negate the duration

Contribute on Github! Edit this section.