获取当前位置的国家/地区和时间戳
我想知道我的应用程序在哪里使用。
以下是获取国家/地区名称的代码:
public string Country = RegionInfo.CurrentRegion.DisplayName;
以下是获取时区的代码:
public void TimeStamp() { TimeZone zone = TimeZone.CurrentTimeZone; // Demonstrate ToLocalTime and ToUniversalTime. DateTime local = zone.ToLocalTime(DateTime.Now); _TimeStamp = local.ToString(); }
我想看看这是否适用于其他位置和IP地址。 我试图使用cyperghost更改我的IP地址,但没有任何改变。 我住在丹麦,上面的代码仍显示“Denmark xx.xx.xx xx.xx.xx”。
如何测试此代码是否真正按照我的意愿运行?
TimeZone.CurrentTimeZone属性返回当前PC的信息。 因此,您可以更改日期和时区并检查: