When delegating formatting of a `LocalDateTime` to...
# kotlinx-datetime
k
When delegating formatting of a
LocalDateTime
to javas datetime utilities, how would I format the full date and time? Right now the value
Copy code
LocalDateTime(
  year = 2023,
  monthNumber = 1,
  dayOfMonth = 17,
  hour = 10,
  minute = 30
)
Gets formatted to
Tuesday, January 17, 2023
with the following invocation:
Copy code
DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL)
            .withLocale(javaLocale)
            .format(dateTime.toJavaLocalDateTime())
I would expect this to format to something like
Tuesday, January 17, 2023 10:30 AM
.
I can’t use a static pattern because the output string needs to be locale sensitive
I think this is probably a java question actually
h
Only a guess: use
toJavaLocalDateTime()
k
Oh whoops I do, I also have a function for
LocalDate
and
LocalTime
.
Copy code
DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL)
            .withLocale(javaLocale)
            .format(dateTime.toJavaLocalDateTime())
Oh I did just see
DateTimeFormatter.ofLocalizedDateTime
. That’s probably what I need.
I needed to pass in separate date and time formatstyles.
Copy code
DateTimeFormatter.ofLocalizedDateTime(
    FormatStyle.FULL,
    FormatStyle.SHORT
).withLocale(javaLocale).format(dateTime.toJavaLocalDateTime())
which yields
Tuesday, January 17, 2023, 10:30 AM
You cannot use the
FULL
format style on
kotlinx.LocalDateTime
for the time component because local date times don’t have timezone info embedded.