Question

I use these lines of code to find out the local time in Gujarat - India, regardless server time set correct or not. But i noticed that this is not working. This line produce SERVER TIME, but not LOCAL TIME. It cause problem if server time change accidentally.

What is the exact solution to to get LOCAL TIME in any country in the world?

Dim zoneId As String = "Indian Standard Time"
Dim tzi As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(zoneId)
Dim result As DateTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, tzi)
Was it helpful?

Solution

You may want to take a look at Noda, a .net port of Joda an open source project for working with dates. This has been ported by Stack Overflows, Jon Skeet.

A couple Link that might be helpful.

http://www.codeproject.com/Articles/78213/Noda-DateTime-Extensions-for-NET

enter link description here

OTHER TIPS

What you want is the correct local time, regardless of the server defined time.

First of all, the server should be configured with the correct date/time. If you can't trust it, I think you have to rely on a service provided by a third party provider to tell you the correct time.

This other question suggests services you can connect to: Web service - current time zone for a city?

If what you want is the client's time, you have to get it through Javascript and send it to the server side.

Good luck!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top