Reputation: 167
My date in the application is displaying as 07/10/2011(dd/MM/yyyy)...I want date to be in the format Oct 7,2011 in android coding. Please help as am newbie to Android
Upvotes: 2
Views: 8038
Reputation: 5045
private void dateformation() {
SimpleDateFormat dateformate = new SimpleDateFormat("MMM dd, yyyy");
Calendar currentDate = Calendar.getInstance();
String currentDateStr = dateformate.format(currentDate.getTime());
Log.i("Infoe ", " " + currentDateStr.toString());
System.out.println("Current date is : " + currentDateStr);
// //=== OR
SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, yyyy");
sdf.applyPattern("MMM dd, yyyy");
Date x = new Date(currentDate.get(Calendar.YEAR) - 1900,
currentDate.get(Calendar.MONTH),
currentDate.get(Calendar.DAY_OF_MONTH));
Log.i("Infoe ", " " + sdf.format(x));
System.out.println(sdf.format(x));
}
Upvotes: 3
Reputation: 15701
SimpleDateFormat dateFormat= new SimpleDateFormat("MMM dd, yyyy", Locale.US); dateFormat.format(new Date(0)));
http://developer.android.com/reference/android/text/format/DateFormat.html http://developer.android.com/reference/java/text/SimpleDateFormat.html
Upvotes: 2
Reputation: 8153
DateFormat f = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.ENGLISH);
String dateString = f.format(new Date());
Upvotes: 3
Reputation: 217
String mydate = java.text.DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime());
TextView _dateText=(TextView)_view.findViewById(R.id.dateTextView);
_dateText.setText(""+mydate);
Upvotes: 0