我想将这个https://cdn-nfs.faireconomy.media/ff_calendar_thisweek.xml加载到VB.NET中的一个表中,我可以使用下面的代码来完成这个任务
Dim xmlDataSet As System.Data.DataSet = New System.Data.DataSet("XML DataSet")
xmlDataSet.ReadXml("https://cdn-nfs.faireconomy.media/ff_calendar_thisweek.xml")
GridControl1.DataSource = xmlDataSet.Tables("event")但日历上有时间。我想根据计算机设置的时间将时间更改为本地时间。
发布于 2020-01-29 20:02:05
我更改了XML的读取方式,并执行了一些计算。这是可行的,但有一个固定的转换。
' What the XML looks like.
' <weeklyevents>
' <event>
' <title>Bank Holiday</title>
' <country>AUD</country>
' <date><![CDATA[01-26-2020]]></date>
' <time><![CDATA[9:00pm]]></time>
' <impact><![CDATA[Holiday]]></impact>
' <forecast />
' <previous />
' </event>
Dim xe As XElement
' read the XML
xe = XElement.Load("http://cdn-nfs.faireconomy.media/ff_calendar_thisweek.xml")
' process each event
For Each el As XElement In xe...<event>
Dim d As DateTime
Dim t As DateTime
If DateTime.TryParse(el.<date>.Value, d) Then
'good date
If DateTime.TryParse(el.<time>.Value, t) Then
'good time
d = d.Add(t.TimeOfDay)
Dim country As String = el.<country>.Value
Dim offs As Integer = -6 'USA CST
'code to figure offset here using country????
'>
d = d.AddHours(offs)
'then update the XML
el.<date>.Value = d.ToString("d MMM yyyy") 'format to your liking
el.<time>.Value = d.ToString("HH:mm:ss")
End If
End If
Next
Dim xmlDataSet As System.Data.DataSet = New System.Data.DataSet("XML DataSet")
xmlDataSet.ReadXml(xe.CreateReader)
GridControl1.DataSource = xmlDataSet.Tables("event")https://stackoverflow.com/questions/59973810
复制相似问题