Get country and timestamp for the current location

风格不统一 提交于 2019-12-02 04:41:20

问题


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:



来源:https://stackoverflow.com/questions/32891515/get-country-and-timestamp-for-the-current-location

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!