asFormattedDateTime
Converts a Unix timestamp (milliseconds) to a human-readable date-time string.
The output format is: "MONTH DAY, YEAR at HOUR:MINUTE AM/PM" (e.g., "January 15, 2024 at 3:45 PM")
Uses the system's current time zone for conversion.
Usage Examples
// Display message timestamp
data class Message(val text: String, val timestamp: Long)
@Composable
fun MessageItem(message: Message) {
Column {
Text(message.text)
Text(
text = message.timestamp.asFormattedDateTime(),
style = MaterialTheme.typography.caption
)
}
}
// Display last sync time
Text("Last synced: ${lastSyncTimestamp.asFormattedDateTime()}")
// Display creation date
val createdAt = System.currentTimeMillis()
Text("Created: ${createdAt.asFormattedDateTime()}")Content copied to clipboard
Examples
1640995200000L.asFormattedDateTime()→ "December 31, 2021 at 11:59 PM"1704067200000L.asFormattedDateTime()→ "January 1, 2024 at 12:00 AM"1704110340000L.asFormattedDateTime()→ "January 1, 2024 at 11:59 AM"
Receiver
Long Unix timestamp in milliseconds (epoch time).
Return
Formatted date-time string in the format "MONTH DAY, YEAR at HOUR:MINUTE AM/PM".
See also
Instant
TimeZone