views:

102

answers:

3

I have a client request that all times be displayed in Pacific Time Zone, regardless of client settings. I'd like to avoid a scenario where I have to call a function for every time display and instead have a single point where I can make the switch.

I'm thinking a custom culture might do the trick, but I wanted to ask before I set off down a potentially blind alley (or miss something trivially easy).

+4  A: 

You could use TimeZone.GetUTCOffset() and DateTime.UtcNow()

Basically get the UTC Time and offset that based on the timezone you are interested in.

Kindness,

Dan

Daniel Elliott
Would that approach need to be applied on each field where a DateTime field was displayed or something I could use on a Master Page and have it cascade down to individual fields? I may be asking for too much, but I was hoping for a DRY solution for the entire site.
KevDog
I wonder if Jon Skeet's Noda time library will handle this scenario when it's complete.
KevDog
+1  A: 

Here's the documentation for Daniel's sample:

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

Mtblewis
A: 

If you store your times in UTC you can convert to whatever you want easily. Michael Brumm has some fairly old code that may help you out with a custom TimeZone. Hard coding an offset will screw you when DST kicks in.

Note: I haven't used this code on Michael's site.

http://www.michaelbrumm.com/simpletimezone.html

Chuck
I'm definitely trying to avoid a hard-coded scenario, so thanks for the reminder!
KevDog