AnnaSmith
AnnaSmith

Reputation: 167

Android: Date Format in Month date year

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

Answers (4)

user1140237
user1140237

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));

    }

Date Format Types

Upvotes: 3

Dheeresh Singh
Dheeresh Singh

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

Niko
Niko

Reputation: 8153

    DateFormat f = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.ENGLISH);
    String dateString = f.format(new Date());

Upvotes: 3

c2dm
c2dm

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

Related Questions