Forked from akshaykalola28/DateFormatterExtensions.kt
Created
March 20, 2023 04:08
-
-
Save e4basil/8092cbe51d798ad7ac9a4f2d2eab71a6 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