Android - format Date to “Day, Month dd, yyyy”

好久不见. 提交于 2019-12-05 06:01:08

Using the values returned from picker

    int selectedYear = 2013;
    int selectedDay = 20;
    int selectedMonth = 11;

    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, selectedYear);
    cal.set(Calendar.DAY_OF_MONTH, selectedDay);
    cal.set(Calendar.MONTH, selectedMonth);
    String format = new SimpleDateFormat("E, MMM d, yyyy").format(cal.getTime());

You can Try This:

SimpleDateFormat sdf = new SimpleDateFormat("EEE-dd-MM-yyyy"); // Set your date format
String currentData = sdf.format(your actual date); // Get Date String according to date format

Here you can see details and all supported format:

http://developer.android.com/reference/java/text/SimpleDateFormat.html

Use a SimpleDateFormat to format the date:

    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, selectedYear);
    cal.set(Calendar.MONTH, selectedMonth);
    cal.set(Calendar.DAY_OF_MONTH, selectedDay);
    SimpleDateFormat sdf = new SimpleDateFormat();
    String DATE_FORMAT = "EE, MMM dd, yyyy";
    sdf.applyPattern(DATE_FORMAT);
    String formattedDate = sdf.format(cal.getTime());
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!