Skip to content

Instantly share code, notes, and snippets.

@carolinemusyoka
Created March 18, 2022 11:05
Show Gist options
  • Save carolinemusyoka/bb5e0c7e1b838022a859b6189d9331e5 to your computer and use it in GitHub Desktop.
Save carolinemusyoka/bb5e0c7e1b838022a859b6189d9331e5 to your computer and use it in GitHub Desktop.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val parsedDate = LocalDateTime.parse(item.created_at, DateTimeFormatter.ISO_DATE_TIME)
val formattedDate = parsedDate.format(DateTimeFormatter.ofPattern("dd.MM.yyyy | HH:mm"))
textCreatedTime.text = formattedDate
} else {
val parser = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")
val formatter = SimpleDateFormat("dd.MM.yyyy | HH:mm")
val formattedDate = formatter.format(parser.parse(item.created_at)!!)
textCreatedTime.text = formattedDate
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment