Skip to content

Instantly share code, notes, and snippets.

@PatilShreyas

PatilShreyas/1-Old.kt Secret

Created Dec 24, 2020
Embed
What would you like to do?
// 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