0

i'm lack of knowledge about timezone cz im never convert a timezone. i have a project which demand me to convert our customer origin timezone into my server timezone by their citycode.

i couldn't find anywhere else by googling. what i found is using

TimeZoneInfo.FindSystemTimeZoneById("Somewhere Else Time").

but what i need is like

TimeZoneInfo.FindTimeZoneByCityCode("DAM")

for damascus timezone.

is there any way or suggestion to do it? any advice would be appreciated.

sorry for my bad english by the way

adam_hdt
  • 21
  • 8
  • `Dim tmz = TimeZoneInfo.FindSystemTimeZoneById("Syria Standard Time") Dim ts As TimeSpan = tmz.BaseUtcOffset If (tmz.SupportsDaylightSavingTime AndAlso tmz.IsDaylightSavingTime(Date.Now)) Then ts = ts.Add(New TimeSpan(1, 0, 0)) End If`. This is the UTC Offset of Damascus current time (+03:00:00). – Jimi Apr 18 '19 at 11:25
  • There is no inbuilt function to get timezone by citycode but i suggest perhaps find a template online, creating your own dictionary of it, so when you enter say "DAM" it will go to find DAM in the dictionary and see that it is Syria Standard time etcs. If you provide more information we could try help, such as let us know what other patrs code is or if you are using a database, cause if so could do some sort of timestamp or similar from the customer end – K.Madden Apr 18 '19 at 11:47
  • The same TimeZoneInfo can be extracted with `Dim tmzs = TimeZoneInfo.GetSystemTimeZones().Where(Function(t) t.DisplayName.Contains("Damascus")).FirstOrDefault()` – Jimi Apr 18 '19 at 11:54
  • Google API available for TimeZone queries: [Web Services: Time Zone API, Developer Guide](https://developers.google.com/maps/documentation/timezone/intro). – Jimi Apr 18 '19 at 12:08
  • Duplicate of https://stackoverflow.com/questions/2583159/net-get-timezone-by-city-or-by-longitude-and-latitude – Mary Apr 18 '19 at 15:32
  • 2
    Hi Adam. Please be more specific about what you mean by "city code". Is there a particular standard you are referencing? For example, are these [IATA Airport codes?](https://en.wikipedia.org/wiki/List_of_airports_by_IATA_code:_D) (If so, then [read this](https://stackoverflow.com/a/20554013/634824).) Or are they something else? – Matt Johnson-Pint Apr 18 '19 at 20:58
  • @Mary I don't think your proposed duplicate will work without a way to get latitude and longitude from the OP's "City Code". I suspect that Matt may be correct in guessing the OP is referring to IATA city/airport codes, in which case there may be publicly accessible travel industry databases that give time zone information for IATA city/airport codes. – Blackwood Apr 18 '19 at 22:55
  • @MattJohnson hi Matt thanks for the response, it answers my problem, the link you gave me is all i need to search actually. appreciate your reference – adam_hdt Apr 22 '19 at 05:31

1 Answers1

0

You can use Bing API to get the timezone from a supplied part of address

Private Function GetTimeZone(ByVal Loc As String) As String
    Dim key As String = "YourBingKeyHere"
    Dim webClient As New Net.WebClient
    Dim result As String = webClient.DownloadString("http://dev.virtualearth.net/REST/v1/TimeZone/" & Loc & "?o=xml&key=" & key)
    Dim xmlDoc As New Xml.XmlDocument()
    xmlDoc.LoadXml(result)
    Dim xmlNodeRdr As New Xml.XmlNodeReader(xmlDoc)
    Dim DS As New DataSet
    DS.ReadXml(xmlNodeRdr, XmlReadMode.InferSchema)
    If DS.Tables.Contains("TimeZone") Then
        If DS.Tables("TimeZone").Rows.Count > 0 Then
            Dim Drow() As DataRow = DS.Tables("TimeZone").Select("Abbreviation IS NOT NULL")
            Dim TimeZoneDataRow As DataRow = Drow(0)
            Dim TimeZone As String = TimeZoneDataRow("Abbreviation").ToString
            Return TimeZone
        Else
            Return Nothing
        End If
    Else
        Return Nothing
    End If
End Function

Usage:

Private Sub ButtonGetTimeZone_Click(sender As Object, e As EventArgs) Handles ButtonGetTimeZone.Click
    MsgBox(GetTimeZone("29910"))
End Sub
Mr. Tripodi
  • 809
  • 1
  • 6
  • 7