jainal
jainal

Reputation: 3021

How to get Date format like this in android?

How to get Date format like this?

Saturday,Dec 11,2011

Edited:

My code portion is like the following:

   String outDate = "";
    Date dT = new Date(year, mon, day);
    SimpleDateFormat sdf = new SimpleDateFormat("EEE,MMM dd,yyyy");
    outDate = sdf.format(dT);

and its output is `Sat,Dec 02,3911` when year = 2011,mon = 11,day = 2;

what is the reason of giving wrong month and year in output?

Upvotes: 0

Views: 2485

Answers (2)

bindal
bindal

Reputation: 1932

Try to use this function

 Date today=new Date();
        public String getCurrentTime()
        {

         SimpleDateFormat sdf = new SimpleDateFormat("EEEE,MM,dd,YYYY");
         String ClsCurrentDay = sdf.format(today);
         return ClsCurrentDay;
        }

Upvotes: 0

Jon Skeet
Jon Skeet

Reputation: 1500395

You can use SimpleDateFormat.

Try:

SimpleDateFormat formatter = new SimpleDateFormat("EEEE,MMM dd,yyyy");
String text = formatter.format(...);

That will use the default locale - adjust accordingly for a different one.

Upvotes: 5

Related Questions