How to get Date format like this in android?

假装没事ソ 提交于 2019-12-20 07:14:35

问题


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


来源:https://stackoverflow.com/questions/8442164/how-to-get-date-format-like-this-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!