Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e4basil/8092cbe51d798ad7ac9a4f2d2eab71a6 to your computer and use it in GitHub Desktop.
Save e4basil/8092cbe51d798ad7ac9a4f2d2eab71a6 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