从城市和州/省或邮编获取时区偏移量 [英] Get Timezone Offset From City and State/Province or Zip

查看:32
本文介绍了从城市和州/省或邮编获取时区偏移量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 asp.net 网站,该网站将使用 EST 时间托管在服务器上,并且可能会在以 EST 运行的计算机/设备上创建.用户将更新与整个北美地区有关的信息.我需要在进行更新的位置的本地时间进行更新的时间戳,而不是服务器或计算机时间.所以我需要能够根据城市和州/省或邮政编码获取位置的偏移量.我已经看过 http://www.earthtools.org/webservices.htm#timezone 并且它需要纬度和经度,而我没有.

I have an asp.net website that will be hosted on a server using EST time and will likely be made on a computer/device operating in EST. The user will be making updates to information pertaining to locations all over North America. I need the timestamp of the update to be made in the local time of the location that the update is being made to, not server or computer time. So I need to be able to get the offset for a location based on either City and State/Province or the Zip code. I've already looked at http://www.earthtools.org/webservices.htm#timezone and it requires latitude and longitude, which I don't have.

推荐答案

您可以从 Google 地图中停用纬度和经度.

You can retireve Latitude and Longitude from Google map.

例如,地址为123 Street, Los Angeles, CA 12345"或地址仅为邮政编码12346"

For example, address is '123 Street, Los Angeles, CA 12345' or address is zip code only '12346'

public void GetCoordinate(string address)
{
    WebClient client = new WebClient();
    Uri uri = new Uri(String.Format("http://maps.google.com/maps/geo?output=csv&q=" + HttpUtility.UrlEncode(address)));

    // Return numbers -
    // 1 = Status Code
    // 2 = Accurancy
    // 3 = Latitude
    // 4 = Longitude
    string[] geocodeInfo = client.DownloadString(uri).Split(',');

    decimal latitude = Convert.ToDecimal(geocodeInfo[2]);                
    decimal longitude = Convert.ToDecimal(geocodeInfo[3]);            
}

我建议以 UTC 格式保存创建/更新时间.当您显示它时,根据用户的时区偏移量(保存在用户的配置文件中)将该 UTC 转换为用户的本地时间.

I suggest save the created/updated time in UTC. When you display it, convert that UTC to user's local time based on the user's time zone offset (which is saved in the user's profile).

这篇关于从城市和州/省或邮编获取时区偏移量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆