As stated by others, when you are outputting dateInSpanish
, you are exposing a Date
instance, which is calling its toString
method and its implementation constructs that string based on a static array containing the words in English
//From java.util.Date
private final static String wtb[] = {
"am", "pm",
"monday", "tuesday", "wednesday", "thursday", "friday",
"saturday", "sunday",
"january", "february", "march", "april", "may", "june",
"july", "august", "september", "october", "november", "december",
"gmt", "ut", "utc", "est", "edt", "cst", "cdt",
"mst", "mdt", "pst", "pdt"
};
When you are declaring the dateFormatter, it is meant to convert a date/string as the following example:
val dateFormatter = SimpleDateFormat("yyyy-MM-dd", localeSpanish)
println(dateFormatter.parse("2017-01-29")) // prints: Wed Jan 29 00:00:00 GMT-02:00 2017
println(dateFormatter.format(Date()) // prints: 2018-07-27 (as today :p)
I think you should use a different mask in order to obtain the formatted string.
But if you are forced to read the date in that format, you would have to declare two formatters:
val readerFormatter = SimpleDateFormat("yyyy-MM-dd", localeSpanish)
val writerFormatter = SimpleDateFormat("d 'de' MMMM 'del' yyyy", localeSpanish)
val readDate: Date = readerFormatter.parse("2017-01-29")
val dateInSpanish: String = writerFormatter.format(readDate)
println(dateInSpanish) // prints: 29 de enero del 2017 (as today :p)