I am using dd-MMM-yyyy format in String format in kotlin in android.
It returns "01-Sept-2022" as a result.
I want "01-Sep-2022" as result.
This issue shows up in android 12 & 13.
@JvmStatic
fun getCurrentDate(format: String): String {
val sdf = SimpleDateFormat(format)
val currentDate = sdf.format(Date())
return currentDate
}
How can I get my desired return value in all versions?
According to @deHaar
SimpleDateFormatreturns the formatted string depending on theLocale. Take a look at all locales and you will find the correct form you want. Below I added a snippet where you can easily find it. If you develop this app for the app store or for other public users you shouldn't change the Locale inSimpleDateFormatbecause the user in this region normally knows this format. TheLocale.getDefaultis also influenced by the Android system settings.returns