Android - 格式日期为“日,月dd,yyyy” [英] Android - format Date to "Day, Month dd, yyyy"

查看:141
本文介绍了Android - 格式日期为“日,月dd,yyyy”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从用户那里得到了他在DatePickerDialog中设置的日期。我得到的日期是这样的格式:

I get from the user, the date he sets in a DatePickerDialog. The date i get is in this format:

int selectedYear, int selectedMonth, int selectedDay

我可以将其格式化为Day,Month dd,yyyy,如下图所示吗?

Can i format it to be like this "Day, Month dd, yyyy" as shown in the picture below?

推荐答案

使用从选择器返回的值

    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());

这篇关于Android - 格式日期为“日,月dd,yyyy”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆