Getting the dates of the current week in Android

2019-01-28 10:32发布

I have these 5 buttons in my program: Monday, Tuesday, Wednesday, Thursday and Friday, which are on my menu screen. What I want now is that when my program starts and my menu screen opens, the buttons contain the days + the dates of the day.

For example, today we're the fourth of may (happy Star Wars day!) and the buttons should be like this:

Monday 04/30 Tuesday 05/01 Wednesday 05/02 Thursday 05/03 Friday 05/04

But when I open the menu screen next monday it should be like this: Monday 05/07 Tuesday 05/08 Wednesday 05/09 Thursday 05/10 Friday 05/11

How can I do this?

2条回答
对你真心纯属浪费
2楼-- · 2019-01-28 10:57

Use the java Calendar class, there is an answer here that could help you devise a solution How to get the first day of the current week and month?

查看更多
来,给爷笑一个
3楼-- · 2019-01-28 11:23

I guess the following two threads is all you will need to get you started. And as Ian mentioned do go through the android Calendar and Date api's. Although I should mention most of the methods of Date api is deprecated. Calendar is generally preferred.

Android Get Current Time and Date

Display Current Time And Date in Android application

查看更多
登录 后发表回答