如何输出没有“-05:00”的 XML UTC 偏移量?
我们有一个 VB.Net 2008 控制台应用程序,其 Module1.vb 从我们的 SQL Server 数据库执行一些查询,并将它们输出为 XML 发送给我们的客户。
问题在于,仅包含时间(例如 1900-01-01 21:26:03.000)的 DateTime 元素被输出到 XML,并附加了 UTC(通用时间)偏移量“-06:00”,例如 13 :56:55.0000000-06:00
当东部时区的客户访问时,该值会转换为一小时后,因此他们请求像 13:56:55.0000000 这样的时间值,而不带 -06.00。
有谁知道该怎么做?
详细信息:
VS 解决方案有一个 Web 参考,我将其称为 WS。 Module1.vb 查询数据库(假设是 tblStats 表),并读取 DataReader 中的数据。对于每一行,它确实:
Dim MyWS As New WS.tblSTATS_TYPE_V1 'which is a complexType in the wsdl
MyWS.Start_Time = CheckTime(MyDataReader("START_TIME"))
...其中 CheckTime 是:
Private Function CheckTime(ByVal Value As Object) As DateTime
If (IsNothing(Value) = True) Then Return New DateTime(0)
If (IsDBNull(Value) = True) Then Return New DateTime(0)
If (IsDate(Value) = False) Then Return New DateTime(0)
Return New DateTime(CDate(Value).TimeOfDay.Ticks, DateTimeKind.Unspecified)
End Function
...但我添加的 DateTimeKind.Unspecified 没有效果。
任何人都可以提供任何指导,我们将不胜感激 - 谢谢!
We have a VB.Net 2008 console app whose Module1.vb does a few queries from our SQL Server database and outputs them as XML to be sent to our customer.
The problem is that DateTime elements that contain only times (e.g., 1900-01-01 21:26:03.000) are being output to the XML with a UTC (Universal Time) offset of “-06:00” appended, e.g., 13:56:55.0000000-06:00
This gets converted to an hour later when accessed by our customer in the Eastern time zone, so they requested Time values like 13:56:55.0000000, without the -06.00.
Does anyone know how to do this?
Details:
The VS solution has a web reference I’ll call WS.
Module1.vb queries the DB, let’s say the tblStats table, and reads thru the data in a DataReader. For each row, it does:
Dim MyWS As New WS.tblSTATS_TYPE_V1 'which is a complexType in the wsdl
MyWS.Start_Time = CheckTime(MyDataReader("START_TIME"))
...where CheckTime is:
Private Function CheckTime(ByVal Value As Object) As DateTime
If (IsNothing(Value) = True) Then Return New DateTime(0)
If (IsDBNull(Value) = True) Then Return New DateTime(0)
If (IsDate(Value) = False) Then Return New DateTime(0)
Return New DateTime(CDate(Value).TimeOfDay.Ticks, DateTimeKind.Unspecified)
End Function
… but my addition of the DateTimeKind.Unspecified had no effect.
Any direction anybody can give would be appreciated - thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 DateTimeOffset 而不是 DateTime 类。它提供了额外的时区信息。
You can use DateTimeOffset instead of DateTime class. It's offers additional timezone information.