String String Date Format Change And Change The Language (locale)
Published:
Know the given string date format,
Make
SimpleDateFormat(THAT_STRING_DATE_FORMAT)
Make
SimpleDateFormat(DESIRED_DATE_FORMAT)
, if you want to change the default language, addLocale
parameterSimpleDateFormat(DESIRED_DATE_FORMAT, Locale(language = "id", country="ID"))
- parse the given string to the desired format to convert string to Date Format
givenStringDate = givenStringDateFormat.parse(givenString)
- format the the desiredDateFormat
yourDesiredDateFormat.format(givenStringDate)
Sample
@SuppressLint("SimpleDateFormat")
fun DateStr.toLoanUIDateFormat() : DateStr {
val backendTransactionFormat = SimpleDateFormat(DATABASE_TRANSACTION_DATE_TIME_FORMAT)
val loanDateFormat = SimpleDateFormat(LOAN_UI_DATE_FORMAT, Locale("id", "ID"))
val date = backendTransactionFormat.parse(this)!!
return loanDateFormat.format(date)
}