Rashad Valliyengal
Rashad Valliyengal

Reputation: 3162

How to set time zone automatically using current location in C#

I need to set my system's time zone automatically using location. when I travel to some other places my system time zone will remains same.When I open my WPF Application and if the internet is connected, is it possible to automatically set the time zone of my system by getting the current time zone by location?

Upvotes: 1

Views: 979

Answers (2)

Matt Johnson-Pint
Matt Johnson-Pint

Reputation: 241778

You would need to

  1. Have a reliable source of location information.

  2. Pass the coordinates determined in step 1 to one of these techniques to get an IANA time zone.

  3. Translate the IANA time zone to a Windows time zone using CLDR mappings, as described here.

  4. Set the Windows time zone using one of the approaches from this answer.

  5. Explain to your users why your application is doing something that is really their own responsibility (or the operating system's responsibility). In other words, don't be sneaky about this. If you're going to do it, it should be a prominent feature of your application, and you should have the user's confirmation before changing anything. Remember, the time zone setting is global for the machine, not just for your application.

IMHO, if this isn't a system utility you're writing, then you should just use the determined time zone instead of trying to set the system to it.

Upvotes: 1

Fluff
Fluff

Reputation: 89

Step one: you need to get the users location I suggest HostIP

Step two: get the time zone of that location Google maps time zone API

then you have to stitch those together.

Upvotes: 0

Related Questions