TheTime
TheTime is an immutable class representing a type-safe signed duration value in milliseconds. It is used in the date namespace context, especially with TheDate (for example: addTime, subtractTime, formatTime).
Interactive example
Syntax
typescript
class TheTime {}
type SerializedTheTime = `time${number}${"-" | "+"}`Relation between TheTime and SerializedTheTime
TheTime: immutable object for duration calculations in date APIs.SerializedTheTime: serialized representation for transport/text storage.- Object -> serialized conversion:
D.serialize(theTime). - Serialized -> object conversion:
D.createTime(serialized)orD.createTimeOrThrow(serialized). TheTimevalues can be positive or negative; they are not absolute by default.
Use cases
- Represent a normalized duration (hours, minutes, seconds) as an immutable value.
- Represent forward and backward offsets (positive or negative durations).
- Add or subtract duration from a date (
TheDate) withaddTimeandsubtractTime. - Format durations with
formatTime.
See also
createTime- Builds aTheTimevalue.serialize- ConvertsTheTimetoSerializedTheTime.addTime- Adds a duration toTheDateorTheTime.
