0

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)
Iain
  • 6,392
  • 2
  • 30
  • 50
  • So you want the user's time who is browsing your site? Then you need to write the time to a hiddenfield via javascript, for example: `myHiddenField.value = new Date().toString();`. You can read that time on the next trip to the server. – Tim Schmelter Jun 28 '12 at 10:49
  • yes, I want the same user's time who's browsing my site. can you please explain a bit more this hiddenfield via javascript? –  Jun 28 '12 at 10:52
  • @netuser Please up Vote correct answers – Ravi Vanapalli Jun 29 '12 at 08:24
  • @Ravia..Total 15 reputations are required for this...please rise up my reputation...by voting up my question also –  Jun 29 '12 at 10:42

2 Answers2

1

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

Iain
  • 6,392
  • 2
  • 30
  • 50
0

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!

Community
  • 1
  • 1
Dante
  • 3,833
  • 4
  • 38
  • 55