-
-
Save PatilShreyas/60581a72f7866da214bb90decc4bc11b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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