Get country and timestamp for the current location

2019-02-26 08:09发布

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条回答
Fickle 薄情
2楼-- · 2019-02-26 08:47

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

查看更多
登录 后发表回答