Drammy
Drammy

Reputation: 988

Timezones in calendar controls

We have a system that schedules appointments and is based in the UK. Project Managers use it to schedule appointments for UK staff as well as Australian staff.

PMs will put an appointment in the schedule for say 9am on Monday but that is independent of location; i.e. when a UK staff member sees it he/she reads it as 9am UK time and when an Australian staff member reads it they read it as 9am Aus time.

I have written an Outlook plugin that displays these bookings and allows selection of them. The problem is that when the plugin runs in Australia it sees the datetime originates from the UK and adds the time difference. So as a result the Australian staff have their appointments offset when they shouldn't be.

I'm using an Infragistics Schedule control and wondered what the best way is to ensure that a 9am appointment appears as 9am in all locations and the offset is NOT applied?

Thanks, Drammy

Upvotes: 1

Views: 1487

Answers (1)

ykatchou
ykatchou

Reputation: 3727

For me, the best way is to always use UTC datetime everywhere in your code. Only when show you can switch (or not) to the good timezone.

http://msdn.microsoft.com/en-us/library/system.datetime.aspx

The Locale / UTC is defined using the DateTimeKind enum ( http://msdn.microsoft.com/en-us/library/shx7s921.aspx )

Always use DateTime.ToUniversalTime() in order to get the DateTime in UTC ( http://msdn.microsoft.com/en-us/library/system.datetime.touniversaltime.aspx )

(Of course the ToLocalTime() exists too).

You should do some tests in order to check everything is looking as expected.

Upvotes: 1

Related Questions