Reputation: 12370
I have an C# application that will be running in a different timezone than where I am developing it. It uses time-based data, and performs calculations and makes decisions based on the time-based data. I want to test using the real data, so was wondering how I could set the time zone or something similar of the application as if I was in the other timezone, and all variables of type DateTime would use this default time?
Upvotes: 5
Views: 11538
Reputation: 750
Is the DateTimeOffset class available to you? (it is not when you use the compact framework). Judging from its APIs, it seems to cover your requirements very well.
Upvotes: 1
Reputation: 111810
DateTime
has only three "modes": DateTimeKind.Utc
, DateTimeKind.Unspecified
and DateTimeKind.Local
. It doesn't make calculations based on the time zone. It doesn't offset it in any way. There is a DateTimeOffset
that could help you (starting with .NET 2.0 SP2)
Upvotes: 4
Reputation: 56769
You would need to set the time zone of the computer that is running the application.
Upvotes: 0
Reputation: 160852
The easiest way would be to just change the timezone on your machine, which is getting picked up by the DateTime
class.
As a general recommendation I would do all time related calculations and storing of times in UTC, only for display purposes convert to the local time zone.
Upvotes: 6