I have to display the date in dd-mm-yy format as per the UI design for our Android app. can any one help me, how to achieve it?
In android, Is it possible to format a date object to mm-dd-yy? If yes, then how?
1.7k views Asked by Shivanand Darur At
4
There are 4 answers
0
On
try this code , it may help you
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
String abs= m3_DateDisplay.getText().toString();
Date testDate = null;
try {
testDate = sdf.parse(abs);
} catch (ParseException e) {
e.printStackTrace();
}
SimpleDateFormat formatter = new SimpleDateFormat("MM-dd-yyyy");
String dateValue=formatter.format(testDate);
0
On
You can done it by SimpleDateFormat
For Example,
android.text.format.DateFormat dateformat = new android.text.format.DateFormat();
dateformat.format("MM-dd-yyyy hh:mm:ss", new java.util.Date());
or
android.text.format.DateFormat.format("MM-dd-yyyy hh:mm:ss", new java.util.Date());
Use
SimpleDateFormat
:http://developer.android.com/reference/java/text/SimpleDateFormat.html
You should store your instance of sdf, if you are planning to be formatting your dates repeatedly. Outside a loop, or as a class member variable, for example.