Challenge: Localizing Dates

localizing date is really straight forward, and there are several ways to implemented

for instance inside crimeReport() you can set a specific locale

private fun getCrimeReport() : String{
        val solvedString = if (crime.isSolved){
            getString(R.string.crime_report_solved)
        } else {
            getString(R.string.crime_report_unsolved)
        }

        val df = DateFormat.getBestDateTimePattern(Locale.FRANCE, Date_Format)
        val dateString = df.format(Date_Format ,crime.date)

        var suspect = if (crime.suspect.isBlank()){
            getString(R.string.crime_report_no_suspect)
        }else {
            getString(R.string.crime_report_suspect, crime.suspect)
        }
        return getString(R.string.crime_report, crime.title, dateString, solvedString, suspect)

    }

or set it in general when you call calendar instance

val calendar = Calendar.getInstance(Locale.FRANCE)

1 Like

I have a question. Will this solution work for all language locales or just for FRANCE?? I’m quite confused.

since each country has different locales, the app follows the defined locale…

1 Like

Okay. Thank you very much

1 Like