[英]Android Display a date of the week
i want to display the days of the week with the date of that week. 我想显示星期几和那一周的日期。 Like today, i want to display for my calendar is like this:
像今天一样,我想为我的日历显示如下:
Mon Tues Wed Thurs Fri Sat Sun
8 9 10 11 12 13 14
Then, when it another week starts, the numbers changes.. So, i experimented with the android calendar class. 然后,当又一个星期开始时,数字发生变化。因此,我尝试了android日历类。 So i came out with this:
所以我出来了:
TextView[] tx = {t1, t2, t3, t4, t5, t6, t7};
SimpleDateFormat curFormater = new SimpleDateFormat("EEE dd");
GregorianCalendar date = new GregorianCalendar();
String[] dateStringArray = new String[7];
for (int day = 0; day < 7; day++) {
dateStringArray[day] = curFormater.format(date.getTime());
date.roll(Calendar.DAY_OF_MONTH, true);
System.out.println("HELLO WORLD DAYS: " + dateStringArray[day]);
tx[day].setText(dateStringArray[day]);
}
just to check if i can attain my objective. 只是为了检查我是否可以实现我的目标。 Well, it is close to what i want.
好吧,它接近我想要的。 The problem is, for example today is Saturday, the output is this:
问题是,例如今天是星期六,输出结果是这样的:
Sat Sun Mon Tue Wed Thur Fri
13 14 15 16 17 18 19
Then, tomorrow..i'm guessing this would become 然后,明天..我猜这将成为
Sun Mon Tue Wed Thur Fri Sat
14 15 16 17 18 19 20
So, the starting day changes. 因此,开始日期发生了变化。 Is there a method/s that will help me attain my objective.
有没有一种方法可以帮助我实现目标。 Maybe i've missed that out while reading the document.
也许我在阅读文档时错过了这一点。 Please Thanks.
拜托了 Any help would be appreciated.
任何帮助,将不胜感激。
Try this 尝试这个
SimpleDateFormat curFormater = new SimpleDateFormat("EEE dd");
GregorianCalendar date = new GregorianCalendar();
String[] dateStringArray = new String[7];
date.set(GregorianCalendar.DATE, date.get(GregorianCalendar.DATE)-date.get(GregorianCalendar.DAY_OF_WEEK));
for (int day = 0; day < 7; day++) {
dateStringArray[day] = curFormater.format(date.getTime());
date.setFirstDayOfWeek(day);
date.roll(Calendar.DAY_OF_MONTH, true);
System.out.println("HELLO WORLD DAYS: " + dateStringArray[day]);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.