Time.second
func Time.second(t: Time.Timed): intTime.second returns the second of t, 0 to 59.
Details
- The second is the whole second the wall clock shows. The fraction below it is dropped, not rounded:
10:00:59.7gives 59. - A second is never 60: parsing the leap second
23:59:60isErr. - On a
Time.ZonedDateTimeit is the second the zone's wall clock shows.
Basic examples
Time.second(Time.plainTime(14, 3, 5)) // 5
Time.second(Time.plainTime(14, 3)) // 0
Time.second(Time.plainTime(0, 0, 59)) // 59Call it through . on any value with a time:
let start = Time.parsePlainTime("09:30:15").unwrap()
start.second() // 15Scope
A Time.PlainDateTime has the second of its time:
let saved = Time.parsePlainDateTime("2026-11-11T18:04:42").unwrap()
saved.second() // 42A Time.ZonedDateTime has the second its zone's wall clock shows:
let landing = Time.parseZoned("2026-11-11T16:20:08+01:00[Europe/Stockholm]").unwrap()
landing.second() // 8A fractional second does not count. The digits after the point belong to Time.millisecond and the fields below it:
let t = Time.parsePlainTime("12:00:07.999").unwrap()
t.second() // 7
t.millisecond() // 999A value typed Time.Timed may hold any of the three types with a time. Pass Time.second by name to read each one:
let lunch = Time.parsePlainDateTime("2026-11-11T12:15:30").unwrap()
let launch = Time.parseZoned("2026-11-11T18:45:01Z[UTC]").unwrap()
let times: Array[Time.Timed] = [Time.plainTime(8, 5, 20), lunch, launch]
times.map(Time.second) // [20, 30, 1]In a pipe, the value is the first argument:
"07:42:10" | Time.parsePlainTime() | Result.map(Time.second) // Ok{ value: 10 }Named arguments
The parameter is named t:
Time.second(t: Time.plainTime(13, 37, 21)) // 21Applications
Read the current second from the clock. Time.now() is an instant, so put it in a zone first:
let s = Time.nowIn(Time.utc).second()
assert(s >= 0 && s <= 59)Write a lap time as M:SS, padding the second to two digits:
func lap(t: Time.PlainTime): string {
let ss = String.from(t.second()).padStart(2, "0")
"${t.minute()}:${ss}"
}
lap(Time.plainTime(0, 4, 7)) // "4:07"
lap(Time.plainTime(0, 12, 45)) // "12:45"Count the seconds since midnight:
func secondsOfDay(t: Time.PlainTime): int {
t.hour() * 3600 + t.minute() * 60 + t.second()
}
secondsOfDay(Time.plainTime(0, 0)) // 0
secondsOfDay(Time.plainTime(1, 2, 3)) // 3723
secondsOfDay(Time.plainTime(23, 59, 59)) // 86399Keep the readings a sensor took on a whole minute:
let readings = ["10:00:00", "10:00:30", "10:01:00", "10:01:15", "10:02:00"]
| Array.map({ Time.parsePlainTime(x).unwrap() })
println(readings.filter({ x.second() == 0 }))[10:00:00, 10:01:00, 10:02:00]Properties and relations
Setting the second with Time.with sets what Time.second reads:
let t = Time.plainTime(10, 15)
for s in Array.range(0, 60) {
let set = t.with(second: s)
assert(set.second() == s)
}Adding a second carries into the minute at 59, and adding a minute leaves the second as it was:
let t = Time.plainTime(9, 30, 59)
assert(t.add(1s).second() == 0)
assert(t.add(1s).minute() == 31)
assert(t.add(1m).second() == 59)Rounding down to the second with Time.round keeps the second and clears the fraction:
let t = Time.parsePlainTime("14:03:05.875").unwrap()
let floored = t.round(Time.Second{}, mode: Time.Floor{})
assert(floored.second() == t.second())
assert(floored.millisecond() == 0)Possible issues
A Time.Instant has no wall clock, so passing one is a compile error:
println(Time.second(Time.now())) // error: cannot use Time.Instant where Time.Timed is expectedPut the instant in a zone first:
let instant = Time.fromEpochMillis(83_000)
instant.inZone(Time.utc).second() // 23A Time.PlainDate has no time:
println(Time.plainDate(2026, 11, 11).second())
// error: Time.second takes Time.Timed first, so a Time.PlainDate does not reach itRounding with the default mode of Time.round can carry into the next minute:
let t = Time.parsePlainTime("10:00:59.7").unwrap()
t.round(Time.Second{}) // 10:01:00
t.round(Time.Second{}).second() // 0There is no second 60. Parsing a leap second is Err, and Time.with constrains it to 59:
Time.parsePlainTime("23:59:60").isOk() // false
Time.plainTime(23, 59, 30).with(second: 60).second() // 59Time.plainTime panics on it:
Time.plainTime(23, 59, 60) // panic: Time.plainTime: second out of range: 60Before 1970, % on the epoch seconds is negative, while the second is always 0 to 59:
let t = Time.fromEpochMillis(-1500)
t.inZone(Time.utc).second() // 58
t.epochMillis() / 1000 % 60 // -1A historical offset can have seconds, so the same instant shows a different second in another zone. Paris kept its local mean time, 9 minutes 21 seconds ahead of UTC, until 1911:
let instant = Time.parseInstant("1900-01-01T12:00:00Z").unwrap()
let paris = instant.inZone(Time.zone("Europe/Paris").unwrap())
instant.inZone(Time.utc).second() // 0
paris.second() // 21
paris.offset() // "+00:09:21"Time.second reads the clock, not a span. A duration literal keeps its seconds as written, and Time.part reads them:
90s.part(Time.Second{}) // 90See also
Time.minute · Time.millisecond · Time.with · Time.round · Time.plainTime · Time.inZone · Time.part · Time.Timed · Time
