【问题标题】:Get country and timestamp for the current location获取当前位置的国家和时间戳
【发布时间】:2015-12-29 17:45:34
【问题描述】:

我想知道我的应用程序在哪里使用。

这是获取国家名称的代码:

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”。

我如何测试这段代码是否真的按我想要的那样工作?

【问题讨论】:

    标签: c# wpf timezone regioninfo


    【解决方案1】:

    TimeZone.CurrentTimeZone 属性返回来自您当前 PC 的信息。因此,您可以更改日期和时区并检查:

    【讨论】:

      猜你喜欢
      • 2015-07-20
      • 1970-01-01
      • 2013-10-19
      • 1970-01-01
      • 2015-11-22
      • 2017-07-06
      • 2015-01-30
      • 2013-01-12
      • 2021-12-04
      相关资源
      最近更新 更多