How to get Date format like this in android?

2019-03-06 00:32发布

问题:

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?

回答1:

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.



回答2:

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