Related Tags:
Asp.Net It was developed by Microsoft to allow programmers to build dynamic web sites, web applications and web services. It was first released in January 2002 with version 1.0 of the .NET Framework, and is the successor to Microsoft's Active Server Pages (ASP) technology. Learn More, C# C# (pronounced "C-sharp") is an object-oriented programming language from Microsoft that aims to combine the computing power of C++ with the programming ease of Visual Basic. C# is based on C++ and contains features similar to those of Java. Learn More, ASP.NET MVC The ASP.NET MVC framework is a lightweight, highly testable presentation framework that (as with Web Forms-based applications) is integrated with existing ASP.NET features, such as master pages and membership-based authentication. The MVC framework is defined in the System.Web.Mvc assembly. Learn More,

How to get the time difference between utc time and local time in C#?

Description:I have .net base website which currently have server time zone set to GMT+5, I need to extract that 5 from it dynamically so that once I change the time zone of the server or deploy the same site on another sever with different time zone, I should be able to extract that time difference in that case.

Posted by: | Posted on: Sep 11, 2020

1 answers

Replies

3

That time difference can be extracted by using the following lines of code.

TimeZone currentTimeZone = TimeZone.CurrentTimeZone;
TimeSpan currentTimeOffset = currentTimeZone.GetUtcOffset(DateTime.Now);

Now we have that time difference in "currentTimeOffset".

Replied by: | Replied on: Sep 11, 2020



Reply
×

Code block Hyperlink bold Quotes block Upload Images

Preview