Using showsMilliseconds the client can control if milliseconds are shown or not. All output will be 0-padded and contains exactly 3 places of milliseconds.
With milliseconds: 2:03:44.232
Without milliseconds: 2:03:44
Usage in SwiftUI
I built this to be able to easily move to/from TimeIntervals in SwiftUI TextFields. A simple example below!
struct TimeIntervalTextField: View {
@Binding var duration: TimeInterval
var body: some View {
TextField("Duration:", value: $duration, format: .timeInterval(showMilliseconds: true), prompt: nil)
}
}
TimeIntervalFormatStyle
Simple ParseableFormatStyle conformace for TimeInterval, with and without milliseconds.
Input
Can accept string timestamps formatted with hours, minutes, seconds, and, optionally, milliseconds. The parser will handle missing 0-padding
Example inputs
Output
Using
showsMilliseconds
the client can control if milliseconds are shown or not. All output will be 0-padded and contains exactly 3 places of milliseconds.Usage in SwiftUI
I built this to be able to easily move to/from TimeIntervals in SwiftUI TextFields. A simple example below!