tl;dr
LocalDate
.now(
ZoneId.of( "Africa/Tunis" )
)
.format(
DateTimeFormatter.ofPattern( "dd.MM.uuuu" )
)
Automatically localize:
LocalDate.now().format( DateTimeFormatter.ofLocalizedDate( FormatStyle.SHORT ) )
Or:
LocalDate
.now( ZoneId.of( "Asia/Kolkata" ) )
.format(
DateTimeFormatter
.ofLocalizedDate( FormatStyle.SHORT )
.withLocale(
new Locale( "hi" , "IN" )
)
)
SimpleDateFormat#toString
As commented by Frisch, your actual code differs from what you showed in your Question. We know that because a value like java.text.SimpleDateFormat@44aa2260
is what is produced by SimpleDateFormat#toString
, having inherited that method implementation from Object#toString
.
So you must be calling something like textView.setText( simpleDateFormat );
.
Another problem: Your formatting pattern is incorrect. The codes are case-sensitive. So mm
should be MM
.
java.time
You are using terrible date-time classes that are now legacy, supplanted years ago by the modern java.time classes defined in JSR 310.
I recommend being explicit about the time zone by which to determine today’s date rather than relying implicitly on the JVM’s current default time zone.
ZoneId z = ZoneId.of( "America/Edmonton" ) ; // Or `ZoneId.systemDefault()`.
LocalDate today = LocalDate.now( z ) ;
Specify your formatting pattern.
DateTimeFormatter f = DateTimeFormatter.ofPattern( "dd.MM.uuuu" ) ;
String output = today.format( f ) ;