I need to convert time to “UTC+03:30 Time Zone” in my web application here is UTC date :
DateTime dt = DateTime.UtcNow;
Is there any function to convert UTC to my time zone or not ? I don’t want to involve myself writing a new function in my application if there is a function in ASP.NET.
The application might be hosted in different server in the world and that’s exactly why I have used UTC date.
I need a function to add 3:30 to the current UTC time.
Are you sure your time zone is really UTC +3:30, all the time, with no daylight savings? If so, you could create a
DateTimeOffsetwith the appropriate offset (3.5 hours). For example:Of course that gives you a
DateTimeOffsetinstead of aDateTime… are you able to use that?A better solution is to use
TimeZoneInfo– for example, you could get the right time zone and call… or you could use
TimeZoneInfobut still get aDateTimeOffset:Personally I would recommend you use
DateTimeOffsetif you can, as the meaning ofDateTimeis somewhat ambiguous and hard to work with correctly..NET’s date and time handling is a bit of a mess, unfortunately 🙁 I have a project called Noda Time which should improve the state of affairs if we ever complete it, but it’s far from production-ready at the moment.