Free Support Forum - aspose.com

How to set TimeZone in calendar

Hi team,
I am wroking on Java. I am using Aspose 18.6. I am exporting calendar into pst. Can you please help for how to set the timezone in calendar.

@Rajmohammad,

Thank you for contacting Aspose Support.
You may change the TimeZone in the calendar using the code snippet given below.

MapiCalendarTimeZoneRule daylightTransitionTime = new MapiCalendarTimeZoneRule();
daylightTransitionTime.setHour(0);
daylightTransitionTime.setMilliseconds(0);
daylightTransitionTime.setMinute(0);
daylightTransitionTime.setMonth(0);
daylightTransitionTime.setSeconds(0);
daylightTransitionTime.setYear(0);
daylightTransitionTime.setDayOfWeek(DayOfWeek.Sunday);
daylightTransitionTime.setPosition(DayPosition.None);

MapiCalendarTimeZoneRule standardTransitionTime = new MapiCalendarTimeZoneRule();
standardTransitionTime.setHour(0);
standardTransitionTime.setMilliseconds(0);
standardTransitionTime.setMinute(0);
standardTransitionTime.setMonth(0);
standardTransitionTime.setSeconds(0);
standardTransitionTime.setYear(0);
standardTransitionTime.setDayOfWeek(DayOfWeek.Sunday);
standardTransitionTime.setPosition(DayPosition.None);

MapiCalendarTimeZoneInfo mapiCalendarTimeZoneInfo = new MapiCalendarTimeZoneInfo();
mapiCalendarTimeZoneInfo.setBias(660);
mapiCalendarTimeZoneInfo.setStandardBias(0);
mapiCalendarTimeZoneInfo.setDaylightBias(0);
mapiCalendarTimeZoneInfo.setDaylightDate(daylightTransitionTime);
mapiCalendarTimeZoneInfo.setStandardDate(standardTransitionTime);
mapiCalendarTimeZoneInfo.setYear(0);
mapiCalendarTimeZoneInfo.setTimeZoneFlags(MapiCalendarTimeZoneFlags.TZRULE_FLAG_RECUR_CURRENT_TZREG | MapiCalendarTimeZoneFlags.TZRULE_FLAG_EFFECTIVE_TZREG);

MapiCalendarTimeZone timeZone = new MapiCalendarTimeZone();
timeZone.setKeyName("UTC-11");
MapiCalendarTimeZoneInfoCollection timeZoneInfos = new MapiCalendarTimeZoneInfoCollection();
timeZoneInfos.add(mapiCalendarTimeZoneInfo);
timeZone.setTimeZoneRules(timeZoneInfos);

mapiCalendar.setStartDateTimeZone(timeZone);
mapiCalendar.setEndDateTimeZone(timeZone);

We hope that this answered your question. Please feel free to reach us if additional information is required.