RFC_1123
RFC 1123 format for dates and times with UTC offset.
Examples of valid strings:
Mon, 30 Jun 2008 11:05:30 GMT
Mon, 30 Jun 2008 11:05:30 -0300
30 Jun 2008 11:05:30 UT
North American and military time zone abbreviations are not supported.
Samples
import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.test.*
fun main() {
//sampleStart
// Parsing a date-time string in the RFC 1123 format and extracting all its components
val rfc1123string = "Mon, 30 Jun 2008 11:05:30 -0300"
val parsed = DateTimeComponents.Formats.RFC_1123.parse(rfc1123string)
check(parsed.toLocalDate() == LocalDate(2008, 6, 30))
check(parsed.toLocalTime() == LocalTime(11, 5, 30))
check(parsed.toUtcOffset() == UtcOffset(-3, 0))
//sampleEnd
}
import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.test.*
fun main() {
//sampleStart
// Formatting a date-time using the given UTC offset in the RFC 1123 format
val today = Instant.fromEpochSeconds(1713182461)
val offset = today.offsetIn(TimeZone.of("Europe/Berlin"))
val formatted = DateTimeComponents.Formats.RFC_1123.format {
setDateTimeOffset(today, offset)
}
check(formatted == "Mon, 15 Apr 2024 14:01:01 +0200")
//sampleEnd
}