I want to have the following date format when performing a System.out.println()
: 31/03/2016
.
Since they pass me the format in a String type in this way "31-03-2016"
, I use the classes
import java.util.Date;
import java.text.DateFormat;
java.text.SimpleDateFormat;
to give it correct format, and I use this form:
SimpleDateFormat d = new SimpleDateFormat("dd-MM-yy");
Date date = d.parse("31-03-2016");
System.out.println(DateFormat.getDateInstance().format(date));
But it shows me:31-03-2016
Since your system is standard with hyphens, you need 2
SimpleDateFormat
:String
toDate
)Date
toString
the desired format)Your code will be something like this:
EXIT
ONLINE-DEMO
ADDED
It happens because you use Java 7 or higher, from this version the way it
Locale.getDefault()
works has changed.Long story short, you have to modify not only the region format, but also change the way the language displays dates.
You can check the problem in this reported bug
SOURCE (IN)