Saturday, 9 April 2016

java - In android, Is it possible to format a date object to mm-dd-yy? If yes, then how?




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?


Answer




Use SimpleDateFormat:



http://developer.android.com/reference/java/text/SimpleDateFormat.html



SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yy");
Log.i("DATE", sdf.format(new Date()));


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.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...