parse

expect fun parse(input: CharSequence, format: DateTimeFormat<UtcOffset> = getIsoUtcOffsetFormat()): UtcOffset(source)

A shortcut for calling DateTimeFormat.parse.

Parses a string that represents a UTC offset and returns the parsed UtcOffset value.

If format is not specified, Formats.ISO is used. Z or +01:30 are examples of valid input.

Throws

if the text cannot be parsed or the boundaries of UtcOffset are exceeded.

Samples

import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.test.*
fun main() { 
   //sampleStart 
   // Parsing a UtcOffset from a string using predefined and custom formats
check(UtcOffset.parse("+01:30").totalSeconds == 5400)
check(UtcOffset.parse("+0130", UtcOffset.Formats.FOUR_DIGITS).totalSeconds == 5400)
val customFormat = UtcOffset.Format { offsetHours(Padding.NONE); offsetMinutesOfHour() }
check(UtcOffset.parse("+130", customFormat).totalSeconds == 5400) 
   //sampleEnd
}