parse
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.
See also
for formatting using the default format.
for formatting using a custom format.
for a version of this function that returns null on faulty 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
}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.
See also
for formatting using the default format.
for formatting using a custom format.
for a version of this function that returns null on faulty 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
}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.
See also
for formatting using the default format.
for formatting using a custom format.
for a version of this function that returns null on faulty 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
}