Reputation: 177
I have web app in azure paas environment. I need to convert the time in different timezone, i have following code which run perfectly fine on dev machine but when i deploy on azure paas environment it throw error
TimeZoneInfo serverTimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(TimeZone.CurrentTimeZone.StandardName);
return TimeZoneInfo.ConvertTimeToUtc(_lastUpdatedDate.Value, serverTimeZoneInfo);
First line throw exception. Error getting value from 'DateCreated' on 'ViewModels.Orders.OrderActivityViewModel'
Upvotes: 1
Views: 794
Reputation: 241475
A few things:
TimeZone
class. It is obsolete. Use only the TimeZoneInfo
class.StandardName
is NOT the same as the Id
for all cases. It is also impacted by OS language, where the Id
is not.TimeZoneInfo.Local.Id
, though there's no point in finding it by Id when you already have it. You'd just use TimeZoneInfo.Local
..ToUniversalTime()
on your original DateTime
or DateTimeOffset
value.WEBSITE_TIME_ZONE
setting (on Windows only), but I don't recommend that. If you have a specific time zone in mind, then you would pass that ID into TimeZoneInfo.FindSystemTimeZoneById
.Upvotes: 1