Created
September 16, 2020 17:07
-
-
Save mksantoki/3df49dd0e3231f6e59cf1e99802ce5b6 to your computer and use it in GitHub Desktop.
This extension is used to format dates. Android date format extension kotlin
This file contains hidden or 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 getDefaultDateTime(date: String): String { | |
val formatter = SimpleDateFormat("dd-MM-yyyy hh:mm aa") | |
return formatter.format(date.toDate()) | |
} | |
fun getDefaultDateTime1(date: String): String { | |
val formatter = SimpleDateFormat("dd-MM-yyyy HH:MM") | |
return formatter.format(date.toDate()) | |
} | |
fun String.toDate( | |
dateFormat: String = "yyyy-MM-dd HH:mm:ss", | |
timeZone: TimeZone = TimeZone.getTimeZone("UTC") | |
): Date { | |
val parser = SimpleDateFormat(dateFormat, Locale.getDefault()) | |
parser.timeZone = timeZone | |
return parser.parse(this) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment