简体   繁体   English

Android / Java-确定日期

[英]Android / Java - Figuring out what the date will be

I'm creating an application that allows the person to select a day within the current week (Days 1/Sunday through 7/Saturday) and see whats on the agenda for that day. 我正在创建一个应用程序,该应用程序允许该人员选择当前周中的某一天(第1天/周日至第7周日/周六),并查看该日的议程。

The functionality I'm looking for is to check what today's date is and what day of the week it is. 我要寻找的功能是检查今天的日期和星期几。 With this information It will show the current weekdays 1 through 7 and I want them to display the date of that day 有了这些信息,它将显示当前的工作日1到7,我希望他们显示当天的日期

Example: Today is Thursday 6/23/2011 (Day 5) I can find this information with the following code: 示例:今天是2011年6月23日(星期四)(第5天),我可以使用以下代码找到此信息:

Calendar c = Calendar.getInstance();
int DayOfWeek = c.get(Calendar.DAY_OF_WEEK);

Calendar c = Calendar.getInstance();
int DayOfWeek = c.get(Calendar.DATE);

I'm trying to figure out what functionality or whatever it is to end up with the following result: 我试图弄清楚什么功能或什么是最终的以下结果:

Sunday : 6/19/2011, Monday : 6/20/2011, Tuesday : 6/21/2011, Wednesday : 6/22/2011, Thursday : 6/23, 2011, Friday: 6/24/2011, Saturday : 6/25/2011 星期日:2011年6月19日,星期一:2011年6月20日,星期二:2011年6月21日,星期三:2011年6月22日,星期四:2011年6月23日,星期五:2011年6月24日,星期六: 2011年6月25日

Select the day of week (as you have above) from the Calendar. 从日历中选择星期几(如上所述)。

Back off that number of days, which is the "start" day. 减少该天数,即“开始”天。 Then add six days, which will be the "end" day. 然后添加六天,这将是“结束”天。

Calendar cal = new GregorianCalendar();
int day = cal.get(Calendar.DAY_OF_WEEK);
cal.add(Calendar.DAY_OF_MONTH, -day);
System.out.println(cal.toString());
cal.add(Calendar.DAY_OF_MONTH, 6);
System.out.println(cal.toString();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM