toInstantUsingOffset

Builds an Instant from the fields in this DateTimeComponents.

Uses the fields required for toLocalDateTime and toUtcOffset.

Almost always equivalent to toLocalDateTime().toInstant(toUtcOffset()), but also accounts for cases when the year is outside the range representable by LocalDate but not outside the range representable by Instant.

Throws

if any of the required fields are not present, out-of-range, or inconsistent with one another.

Samples

import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   // Obtaining an Instant from the parsed data using the given UTC offset
val rfc1123Input = "Sun, 06 Nov 1994 08:49:37 +0300"
val parsed = DateTimeComponents.Formats.RFC_1123.parse(rfc1123Input)
val instant = parsed.toInstantUsingOffset()
check(instant == Instant.parse("1994-11-06T08:49:37+03:00"))
val localDateTime = parsed.toLocalDateTime()
val offset = parsed.toUtcOffset()
check(localDateTime.toInstant(offset) == instant) 
   //sampleEnd
}