Detect Timezone of client using c# [duplicate] - c#

This question already has answers here:
How to get client date and time in ASP.NET?
(6 answers)
How to detect the timezone of a client?
(4 answers)
Closed 6 years ago.
I am using ASP.NET Webforms to get the data of client. till now I figured out the IP address of client and the city & country of the client. I am trying to find a way of how to retrieve the time zone by using its IP Address or country name or city name. I have googled and couldn't find any appropriate answer as everyone talks about injecting javascript to get timezone.
My question is: Is there any way to find timezone of the client? If so then how?`

It is not possible to do this in a reliable way purely with C#. The HTTP spec does not provide any hints of the client's time zone.
You can guess at a client's time zone by using IP geolocation, and there are many free and commercial services that provide time zone information. However there is only a limited degree of accuracy with such an approach.
Even with JavaScript, the current solutions can still only guess the client's time zone. There are improvements happening for this with in the ECMAScript Intl API, but not all browsers fully implement that yet. See more here.
Ultimately, if you need to know the time zone of the client from your back end code, the best thing to do is to ask the user. Provide a time zone picker somewhere in your application.
You may also find this related answer useful.

Have you tried using the TimeZoneInfo Class
It represents any time zone in the world.
https://msdn.microsoft.com/en-us/library/system.timezoneinfo(v=vs.110).aspx

Related

Is there any possible way to get TimeZone by ZipCode in C#? [duplicate]

This question already has answers here:
Mapping US zip code to time zone [closed]
(12 answers)
Closed 2 years ago.
I have a list of around 400 zip codes. I need to use this code's time zone in the application. For Example:- If my code zip code 35242, after googling I found the time zone for 35242 is GMT-5. Now in the application, I need to add DateTime.Now.AddHours(-5). Is there any way to do this from code or do I have to search the timezone for all zip codes and do it manually?
Q: Is there any way to get time zone from zip code programmatically?
A: Sure. There are lots of databases, programming libraries and web services available. Some paid, some free; some "static" (e.g. a .csv download), others dynamic (e.g. a REST API).
SUGGESTION: Consider trying Google's Timezone API
Getting started with Google Maps Platform
Getting started with Google TimeZone API
C#/VB/Net example code

C# - DateTime.Now.TimeOfDay is different on my other comptuter by 2 seconds, how do I get accurate time? [duplicate]

This question already has answers here:
How to Query an NTP Server using C#?
(6 answers)
Closed 3 years ago.
I need to get the same time on all Instances of my program. How do I do that. DateTime.Now is not accurate(is different on different hardware) enough, I need to get the Time down to 100 ms difference-precision.
You don't want it read locally from each computer, as you don't know that each PC's clock is perfectly in sync (and you can see that they aren't).
So you have two options:
Write something on each computer to maintain precise time.
Get a web based time and all of your computers will be reading the same data. Here is an example from SO: How to get DateTime from the internet?

Display current datetime depending on client [duplicate]

This question already has answers here:
How to handle Azure's UTC time
(2 answers)
Closed 8 years ago.
I am currently saving the datetime.utcnow in the database on azure but im not sure how to display the correct time depending on the client.
Should I be using utc?
Should I save the timezone so I can recalculate the time?
Can I use the culture to change the time to the client time?
Your best option is to store the DateTime as UTC time and adjust it to local time (for the user's current location) each time you read it from the database.
You can use JavaScript to determine the timezone of the user:
new Date().gettimezoneOffset()

Time based serial key generation for PC Software [duplicate]

This question already has answers here:
How can I create a product key for my C# application?
(14 answers)
Closed 9 years ago.
How can i generate serial key for the C# Desktop Application (Windows application) ?
E.g. Software expires after a month. (Trial version).
If user changes Machine time then hoe could it be possible to validate the software for the specified time ?
There are many ways you can generate serial keys for your application in C#. You will most likely have make some sort of trade off between the simplicity (ie. the length of the key, readability, etc), and the security of a particular system.
I would recommend Software Protector(http://softwareprotector.clizware.net/) and SKGL (https://skgl.codeplex.com/). Software Protector would give you a user interface where you can generate your keys and SKGL API would allow you to validate those inside your own application. If you like, you can also include the source code of SKGL API (currently available in C# and VB.NET). You can set a time limit from 0 to 999, 8 custom features, and machine locking.
Regarding the time changing issue, the only way I see is to look up the local time (for that time zone) online using time.windows.com and check if that is equal to the current time on the pc. Please check this article: https://skgl.codeplex.com/discussions/472444
Please note that I am developing both SKGL API and Software Protector, which means that my answer might have a slight tendency!

Create 30 day Trial Version [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
how can i make my product as a trial version for 30 days?
I want to create a 30 day trial version of my software, I can record the installation date and compare it with the sysdate of the machine. The problem is how to validate that the user changed the sysdate and how much time I have to adjust in my trial period.
One option is to consume a web service, but the problem are the offline customers.
This is stand alone windows application.
Is there any method I can use to count XX days since the installation?
There is no way, which is one hundred percent reliable. You can query online website for current date, and users will reverse the requests with network sniffer and spoof the server. You can compare most recent temporary file date to detect clock rewinding, but it might cause other issues. You can do something else, and users will patch your code to remove the protection.
Do it the way that makes sense to you, still without having an obsession around it. Your code will stay hackable anyway. You will be better of reasonably pricing it so that hacking makes no sense.

Categories