MpLocalTime
A time of day — no date, no timezone. The right type for business hours, alarm times, and recurring schedule patterns.
When to use MpLocalTime
- Business hours ("open 9:00 to 17:00")
- Alarm or reminder times
- Time-of-day patterns in scheduling
- Time slots and availability windows (see MpLocalTimeSlot)
Creating
import io.peekandpoke.ultra.datetime.MpLocalTime
val time = MpLocalTime.of(14, 30, 15) // 14:30:15
val withMillis = MpLocalTime.of(14, 30, 15, 500) // 14:30:15.500
val parsed = MpLocalTime.parse("14:30:15")
val maybe = MpLocalTime.tryParse("not-a-time") // null
// From raw units
val fromMillis = MpLocalTime.ofMilliSeconds(52_215_000L) // 14:30:15
val fromSeconds = MpLocalTime.ofSecondOfDay(52_215L) // 14:30:15
// Constants
val midnight = MpLocalTime.Min // 00:00:00.000
val endOfDay = MpLocalTime.Max // 23:59:59.999
val noon = MpLocalTime.Noon // 12:00:00.000 Properties
val time = MpLocalTime.of(14, 30, 15, 500)
time.hour // 14
time.minute // 30
time.second // 15
time.milliSecond // 500 What MpLocalTime can do
MpLocalTime is deliberately small. A time of day without a date can only support a few operations safely:
import kotlin.time.Duration.Companion.hours
import kotlin.time.Duration.Companion.minutes
val time = MpLocalTime.of(14, 30)
// Add and subtract Duration — wraps around midnight
val later = time.plus(2.hours) // 16:30
val earlier = time.minus(30.minutes) // 14:00
val wrapped = time.plus(12.hours) // 02:30 (next day, wraps)
// Duration between two times
val other = MpLocalTime.of(17, 0)
val diff = other - time // 2h 30m
// Convert to raw milliseconds of day
time.inWholeMilliSeconds() // 52200000 What MpLocalTime does not have
A time of day has no calendar context, so these operations are not available:
- No date components (
.year,.month,.day) - No calendar arithmetic (
plusDays,plusMonths) - No conversion to instant or zoned datetime (where would it go without a date?)
- No timezone offset information
To combine a time with a date, use MpLocalDate.atTime():
val date = MpLocalDate.of(2025, 3, 15)
val time = MpLocalTime.of(14, 30)
// Combine into a LocalDateTime
val dt = date.atTime(time) // 2025-03-15T14:30
// Or directly into a ZonedDateTime
val zoned = date.atTime(time, MpTimezone.of("Europe/Berlin")) Formatting
val time = MpLocalTime.of(14, 30, 15)
time.toIsoString() // "14:30:15.000"
time.formatHhMm() // "14:30"
time.formatHhMmSs() // "14:30:15"
time.format("HH:mm") // "14:30" Time constants
| Constant | Value |
|---|---|
MILLIS_PER_SECOND | 1,000 |
MILLIS_PER_MINUTE | 60,000 |
MILLIS_PER_HOUR | 3,600,000 |
MILLIS_PER_DAY | 86,400,000 |
JVM interop
// MpLocalTime -> java.time.LocalTime
val javaTime: java.time.LocalTime = mpTime.jvm
// java.time.LocalTime -> MpLocalTime
val mpTime: MpLocalTime = javaTime.mp