How to get Date format like this in android?

2019-03-06 00:25发布

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?

2条回答
干净又极端
2楼-- · 2019-03-06 00:43

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.

查看更多
再贱就再见
3楼-- · 2019-03-06 00:46

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;
        }
查看更多
登录 后发表回答