From 3114b2eeaac6afd5a72f5750a16b67a5bb8d80e4 Mon Sep 17 00:00:00 2001 From: ahmedmadhoun1 Date: Thu, 29 Jun 2023 15:47:25 +0300 Subject: [PATCH] Allow localised date format --- .../samples/apps/nowinandroid/core/ui/NewsResourceCard.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt index 009fb1249..c9a327881 100644 --- a/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt +++ b/core/ui/src/main/java/com/google/samples/apps/nowinandroid/core/ui/NewsResourceCard.kt @@ -70,6 +70,7 @@ import kotlinx.datetime.Instant import kotlinx.datetime.toJavaInstant import java.time.ZoneId import java.time.format.DateTimeFormatter +import java.time.format.FormatStyle import java.util.Locale import com.google.samples.apps.nowinandroid.core.designsystem.R as DesignsystemR @@ -230,8 +231,11 @@ fun dateFormatted(publishDate: Instant): String { } } - return DateTimeFormatter.ofPattern("MMM d, yyyy") - .withZone(zoneId).format(publishDate.toJavaInstant()) + return DateTimeFormatter + .ofLocalizedDate(FormatStyle.MEDIUM) + .withLocale(Locale.getDefault()) + .withZone(zoneId) + .format(publishDate.toJavaInstant()) } @Composable