URL:http://stackoverflow.com/questions/454315/how-do-you-format-date-and-time-in-android
| Use the standard Java DateFormat class. For example to display the current date and time do the following: You can initialise a Date object with your own values, however you should be aware that the constructors have been deprecated and you should really be using a Java Calendar object. | |||||||||
|
| In my opinion, I android.text.format.DateFormat.getDateFormat(context) make me confused because this method returns java.text.DateFormat rather than android.text.format.DateFormat - -". So, i use fragment code as below for get current date in my format In addition, you can use others format follow http://developer.android.com/reference/android/text/format/DateFormat.html | ||||
|
| This will do it: | |||||
| |
| Although accepted, the answer wasn't really correct, because getDateFormat(getApplicationContext()) method returns date format only, not a date and time when having year, month, day, hour and minuteYou can find correct answer here. | |||
| |
| Please note that in the answer above selected by the owner as the best answer, in the line: DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(getApplicationContext());the returned dateFormat is of type java.text.DateFormat (and NOT android.text.format.DateFormat) |