Get country and timestamp for the current location

2019-02-26 08:11发布

问题:

I want to know where my application is used.

Here is the code for getting the country name:

public string Country = RegionInfo.CurrentRegion.DisplayName;

Here is the code to get the timezone:

public void TimeStamp()
{
    TimeZone zone = TimeZone.CurrentTimeZone;
    // Demonstrate ToLocalTime and ToUniversalTime.
    DateTime local = zone.ToLocalTime(DateTime.Now);

    _TimeStamp = local.ToString();
}

I want to see if this works for other locations and IP addresses. I have tried to change my IP address using cyperghost, but nothing changed. I live in Denmark and the code above still shows "Denmark xx.xx.xx xx.xx.xx".

How can I test if this code actually works as I want it to?

回答1:

TimeZone.CurrentTimeZone property returns information from your current PC. So, you can change your date and timezone and check: