

The above code is from the package which we have imported and what it does is we have a database of the different type of the timezone from one there is a IANA/Olson Time Zone Database. So, firstly, let's just narrow down the above code to understand more about the conversion functions.
#Time zone conversion windows
Now, we have unspecified the kind, and we are moving towards getting our windows type time zone. TimeZoneInfo ut = TimeZoneInfo.FindSystemTimeZoneById(TZConvert.IanaToWindows(timezone)) DateTime localDateTime = DateTime.SpecifyKind(localDateTime, DateTimeKind.Unspecified) NOTE: Mostly the Developer uses the ToUnivesalTime() function to convert time to UTC, but it results in inconsistent output if timezone is not same, which basically takes deployed environment's timezone as reference. So, we have to mark the kind as unspecified.

Over here, we have specified this date time as unspecified because we have a timezone we want to convert it to the UTC time with respect to the timezone which we have. This method is used to create a new DateTime object which has the same number of ticks as the specified DateTime but is designated as either local time, Coordinated Universal Time (UTC), or neither, as indicated by the specified DateTimeKind value. localDateTime = DateTime.SpecifyKind(localDateTime, DateTimeKind.Unspecified)

Convert to UTC with Specific Time ZoneĬurrently, we are using the c# for this function, and we can use it as a library as well. Now, let's quickly move on to our solution and what we are going to do over here is we are going to take a current time zone and time and with respect to the timezone we are going to convert it to the UTC time zone to store the time in the database, and we are going to perform the operation on the UTC time zone and at the time of getting the data from the database we are again going to convert it to the current time with respect to timezone.
#Time zone conversion install
I have added two commands, one is with the -Version which is optional if you want to install it with the specific version, and if you want to install the latest package then you can use the first command. Install-Package TimeZoneConverter -Version 5.0.0 To install it with the help of Package Manager Console, Go To Tools → NuGet Package Manager → Package Manager Console and copy the following command and paste it inside the console and install it.And then search the TimeZoneConverter in Browse tab and install it.

