获得时差抵消市州/省或邮政编码 [英] Get Timezone Offset From City and State/Province or Zip

查看:171
本文介绍了获得时差抵消市州/省或邮政编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp.net网站,将利用EST时间服务器上托管,并可能会在计算机/设备在运行美国东部时间上进行。用户将进行更新,以有关北美各地位置的信息。我需要在该更新正在于,不服务器或计算机时所取得的位置的本地时间要进行的更新的时间戳。所以,我需要能够基于两个城市和省/州或邮编code,以获得偏移的位置。我已经看了 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.

推荐答案

您可以从谷歌地图retireve经度和纬度。

You can retireve Latitude and Longitude from Google map.

例如,地址是123街,洛杉矶,CA 12345或地址邮编code只有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天全站免登陆