roundedTo

Returns this time, rounded to match the precision of a given unit. If the time is halfway between whole values of the unit, it will be rounded up.

fun Time.roundedTo(unit: TimeUnit): Time
fun OffsetTime.roundedTo(unit: TimeUnit): OffsetTime

Returns this date-time, rounded to match the precision of a given unit. If the time is halfway between whole values of the unit, it will be rounded up.

fun DateTime.roundedTo(unit: TimeUnit): DateTime
fun OffsetDateTime.roundedTo(unit: TimeUnit): OffsetDateTime

Returns this date-time, rounded to match the precision of a given unit. If the time is halfway between whole values of the unit, it will be rounded up.

Due to daylight savings time transitions, there a few complexities to be aware of. If the new local time falls within a gap (meaning it doesn't exist), it will be adjusted forward by the length of the gap. If it falls within an overlap (meaning the local time exists twice), the offset will be retained if possible. Otherwise, the earlier offset will be used.

fun ZonedDateTime.roundedTo(unit: TimeUnit): ZonedDateTime

Returns this instant, rounded to match the precision of a given unit. If the time is halfway between whole values of the unit, it will be rounded up.

fun Instant.roundedTo(unit: TimeUnit): Instant