Skip to content Skip to sidebar Skip to footer

How To Set Java.util.calendar To A Specific Time Period In The Future

I'm using Java's calendar to set an alarm at a specific date and time. I know how to make this work when the user selects a specific date and time. For example, if the user wants t

Solution 1:

You want to look at calendar.add , it will increment the next field if you get overflow.

http://developer.android.com/reference/java/util/Calendar.html

Solution 2:

You can also try this

 Calendar c = Calendar.getInstance();
 c.setTime(new Date()); // 
 c.add(Calendar.YEAR, 5); // Add 5 years to current year
 c.add(Calendar.DATE, 5); // Add 5 days to current date
 c.add(Calendar.MONTH, 5); // Add 5 months to current month
 System.out.println(c.getTime());

Solution 3:

You can try the calendar.set methods specified in this links. How to set the calendar in android for particular hour This worked for me , when I wanted to run the service on the specified time.

Post a Comment for "How To Set Java.util.calendar To A Specific Time Period In The Future"