如何只从XML接收时间 [英] How to receive only time from XML

查看:122
本文介绍了如何只从XML接收时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我,

i从XML获取日期时间字段(2017-06-19T14:45:00:00)

但我只需要时间使用vb.net



我尝试过:



Dim o As String =(info.Element(onairtime)。Value)

Dim value As DateTimeOffset = DateTimeOffset.ParseExact(o,yyyy-MM-dd \THH:mm:ss,CultureInfo .InvariantCulture)

Please help me,
i am getting date time field from XML(2017-06-19T14:45:00:00)
But i need to get only time using vb.net

What I have tried:

Dim o As String = (info.Element("onairtime").Value)
Dim value As DateTimeOffset = DateTimeOffset.ParseExact(o, "yyyy-MM-dd\THH:mm:ss", CultureInfo.InvariantCulture)

推荐答案

您可以获取完整的 DateTime 对象,只需提取时间值。或者您可以解析文本字符串并忽略 T 左侧的数字。
You can get the complete DateTime object and just extract the time value. Or you can parse the text string and ignore the numbers to the left of the T.


这样的事情:

Something like this:
Dim date1 As Date = Date.Now
Console.WriteLine("the time is " + date1.TimeOfDay.Tostring())

或者是字符串:

Or for a string:

Dim date2 As String = "2017-06-19T14:45:00:00"
Console.WriteLine("the time is " + date2.Split(New Char() {"T"c})(1))


这篇关于如何只从XML接收时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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