Reputation: 2186
The date/time data in the database is stored as Oracle Time Stamp with Time Zone (02-FEB-2013 13:25:00 US/PACIFIC). When I read the data I need to determine the difference between this time and user's current local time. Using above, I can get user's local time offset:
OracleTimeStampTZ dtzLastActivity = new OracleTimeStampTZ(dr["LAST_ACTIVITY_TZ"].ToString());
TimeSpan tsOffset = dtzLastActivity.GetTimeZoneOffset();
Can I get the local time, maybe using TimeZoneInfo, knowing only the offset, so I can then subtract the time in database from local time to get the difference?
Upvotes: 1
Views: 184
Reputation: 241673
US/Pacific
is an IANA/Olson time zone identifier - not a Windows time zone id. So you can't use the TimeZoneInfo
classes for it.
Instead, use a TZDB implementation, such as NodaTime. It has full awareness of these types of time zones, and can do the type of calculation you are looking for.
BTW - US/Pacific
as actually an alias for America/Los_Angeles
. You can find a list of these time zones here.
UPDATE
Sorry, I overlooked that you are using OracleTimeStampTZ
. This appears to already implement the TZDB, so you should be able to use it directly. Try the following:
var span = DateTime.UtcNow - dtzLastActivity.ToUniversalTime().Value;
Upvotes: 1