to Utc Offset
Builds a UtcOffset from the fields in this DateTimeComponents.
This method uses the following fields:
offsetIsNegative (default value is
false
)offsetHours (default value is 0)
offsetMinutesOfHour (default value is 0)
offsetSecondsOfMinute (default value is 0)
Throws
if any of the fields has an out-of-range value.
Samples
import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.test.*
fun main() {
//sampleStart
// Obtaining a UTC offset from the parsed data
val rfc1123Input = "Sun, 06 Nov 1994 08:49:37 +0300"
val parsed = DateTimeComponents.Formats.RFC_1123.parse(rfc1123Input)
val offset = parsed.toUtcOffset()
check(offset == UtcOffset(3, 0))
//sampleEnd
}