We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Yearly recurrency example

Hi,

I want to make a recurrency that occurs yearly , every April 15.
How can I do that ?

Thanks

Hi,


Thank you for contacting Aspose support team.

Following is the sample code to create yearly recurrence on 15th of April.

<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:navy”>public static void
MapiCalendar_YearlyFifteenthOfApril()

{

MapiCalendar mapiMonthly =
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>null
;

java.util.Calendar calendar =
java.util.Calendar.getInstance(java.util.TimeZone.getTimeZone(
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:green”>“GMT”
));



calendar.set(
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:blue”>2016, Calendar.<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:#660E7A”>APRIL
, <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:blue”>15, <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:blue”>0, <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:blue”>0, <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:blue”>0);



Date startDate = calendar.getTime();



calendar.set(
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:blue”>2016, java.util.Calendar.<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:#660E7A”>APRIL
, <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:blue”>15, <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:blue”>0, <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:blue”>0, <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:blue”>0);



Date endDate = calendar.getTime();



<span style=“font-size:
9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>try

{

MapiCalendar cal =
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>new
MapiCalendar();

cal.setLocation(
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:green”>“Location”
);

cal.setSubject(
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:green”>“Subject”
);

cal.setBody(
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:green”>“Description”
);

cal.setStartDate(startDate);

<span style=“font-size:
9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:gray”>// Set the yearly recurrence

MapiCalendarMonthlyRecurrencePattern rec = <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>new
MapiCalendarMonthlyRecurrencePattern();

rec.setDay(
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:blue”>15);

rec.setPeriod(
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:blue”>12);

rec.setPatternType(MapiCalendarRecurrencePatternType.<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:#660E7A”>Month
);

rec.setEndType(MapiCalendarRecurrenceEndType.<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:#660E7A”>NeverEnd
);

rec.setOccurrenceCount(
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:blue”>0);


cal.getRecurrence().setRecurrencePattern(rec);

cal.save(<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:green”>“FifteenthOfApril.msg”
, AppointmentSaveFormat.<span style=“font-size:9.0pt;
font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;color:#660E7A”>Msg
);

}

<span style=“font-size:
9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>catch
(Exception ex)

{

System.
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:#660E7A”>out
.println(ex.getMessage());

}

}