我怎样才能在Android上的当前周中的每一天? [英] How can I get all the days of the current week in android?

查看:141
本文介绍了我怎样才能在Android上的当前周中的每一天?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在当前周的所有天字符串数组。我怎样才能达致这?先谢谢了。

I want to get all the days in the current week in an array of Strings. How can I acheive this? Thanks in advance.

推荐答案

我的认为的你想这样的事情......假设你总是希望周从星期一开始,和MM的日期格式/ DD / YYYY。

I think you want something like this... assuming you always want weeks starting on Monday, and a date format of "MM/dd/yyyy".

DateFormat format = new SimpleDateFormat("MM/dd/yyyy");
Calendar calendar = Calendar.getInstance();
calendar.setFirstDayOfWeek(Calendar.MONDAY);
calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);

String[] days = new String[7];
for (int i = 0; i < 7; i++)
{
    days[i] = format.format(calendar.getTime());
    calendar.add(Calendar.DAY_OF_MONTH, 1);
}

虽然我的认为的这是正确的,我个人使用乔达的时间尽可能地 - 我知道这是在Android上稍微麻烦,你就更有可能有空间的关注。

While I think that's correct, I personally use Joda Time wherever possible - I'm aware that's slightly trickier on Android where you're more likely to have space concerns.

这篇关于我怎样才能在Android上的当前周中的每一天?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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