Skip to content

Instantly share code, notes, and snippets.

@PatilShreyas
Created December 24, 2020 12:48
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 PatilShreyas/60581a72f7866da214bb90decc4bc11b to your computer and use it in GitHub Desktop.
Save PatilShreyas/60581a72f7866da214bb90decc4bc11b to your computer and use it in GitHub Desktop.
// MainApp.kt
fun main() {
val date = Date()
val formattedDate = DateUtils.formatDate(date, "yyyy-MM-dd")
}
// DateUtils.kt
object DateUtils {
fun formatDate(date: Date, pattern: String): String {
return SimpleDateFormat(pattern).format(date)
}
}
// MainApp.kt
fun main() {
val date = Date()
val formattedDate = date.format("yyyy-MM-dd")
}
// DateExt.kt
fun Date.format(pattern: String): String = SimpleDateFormat(pattern).format(this).format(this)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment