Java: get any day of the week from the calendar
Using the calendar, I can get the week, year and all the details of the day How can I browse a specific day that week?
Say, calendar get(Calendar.DAY_OF_WEEK); Return to 3, which means a Tuesday Now, I want to go to Friday or any day of that week on Friday How can I do this?
Thank you for your reply I think I need to make the scene clearer Basically, I try to disable email alerts in the system for a specified period of time I get the following value: disablestart = "friday-19:00" disableend = "sunday-19:00"
Now, I need to verify whether email should be sent at a specific time For example, if today = Thursday, e-mail can be sent at any time, but if today = Saturday, e-mail can not be sent at any time according to the above value
Solution
If I understand correctly, I can use calendar Set (field, value) method
SimpleDateFormat f = new SimpleDateFormat("dd-MM-yyyy"); Calendar c = Calendar.getInstance(); System.out.println(c.get(Calendar.DAY_OF_WEEK)); System.out.println(f.format(c.getTime())); c.set(Calendar.DAY_OF_WEEK,Calendar.TUESDAY); System.out.println(c.get(Calendar.DAY_OF_WEEK)); System.out.println(f.format(c.getTime()));
Generate output
6 08-10-2010 3 05-10-2010