Last active
March 20, 2023 04:08
-
-
Save akshaykalola28/ec240ff00a97ebe91c1c06c1ea37dcbc to your computer and use it in GitHub Desktop.
Kotlin extenstion for date format in android
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
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