The solution is really simple
I figured out the following method for setting the dates in the entities. Basically you grab the difference between the current local DateTime, and the current UTC DateTime like this:
Code Snippet
- TimeSpan utcOffset = DateTime.Now - DateTime.UtcNow;
Then when you create the entity just add the utcOffset to any date values.
Code Snippet
- // figure out the offset between now and UTC time, so that we can store the dates as UTC dates.
- TimeSpan utcOffset = DateTime.Now - DateTime.UtcNow;
- Appointment apt = new Appointment()
- {
- dwe_AppointmentType = appointmentType,
- Subject = account.Name,
- IsAllDayEvent = true,
- ScheduledStart = aptDate + utcOffset,
- ScheduledEnd = aptDate.AddDays(1) + utcOffset,
- dwe_country = account.dwe_CountryId,
- RegardingObjectId = new EntityReference()
- {
- Id = account.AccountId,
- LogicalName = "account"
- },
- OwnerId = account.OwnerId,
- };
and it's as simple as that.
No comments:
Post a Comment