Skip to content

Instantly share code, notes, and snippets.

@akshaykalola28
Last active March 20, 2023 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save akshaykalola28/ec240ff00a97ebe91c1c06c1ea37dcbc to your computer and use it in GitHub Desktop.
Save akshaykalola28/ec240ff00a97ebe91c1c06c1ea37dcbc to your computer and use it in GitHub Desktop.
Kotlin extenstion for date format in android
import java.text.SimpleDateFormat
import java.util.*
fun String.toDate(format: String = "yyyy-MM-dd HH:mm:ss"): Date? {
val dateFormatter = SimpleDateFormat(format, Locale.getDefault())
return dateFormatter.parse(this)
}
fun Date.toStringFormat(format: String = "yyyy-MM-dd HH:mm:ss"): String {
val dateFormatter = SimpleDateFormat(format, Locale.getDefault())
return dateFormatter.format(this)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment