[英]Change the date format read from XML file - vb.net
That's my problem: I read the date from a xml file in the yyyy-mm-ddThh:mm:ss
format. 那是我的问题:我从xml文件中以yyyy-mm-ddThh:mm:ss
格式读取日期。 Example: <Date_Creation>2015-06-10T08:56:44</Date_Creation>
示例: <Date_Creation>2015-06-10T08:56:44</Date_Creation>
Then I want to write this date in a new file but only in this format: 06/10/2015
(that is MM/dd/yyy
, without the time). 然后,我想将此日期写到一个新文件中,但只能使用以下格式: 06/10/2015
(即MM/dd/yyy
,没有时间)。
What I tried at first it was: 我最初尝试的是:
Date_Creation = Date.Parse(noeudEnf.InnerText.ToString)
But then I get the time and I don't want it. 但是后来我得到了时间,我不想要它。 So I tried to do this: 所以我尝试这样做:
Date_Creation = DateTime.ParseExact(Date_Creation, "dd/MM/yyyy", CultureInfo.InvariantCulture)
I thought the problem was the "-" instead of "/" in the xml file. 我认为问题是xml文件中的“-”而不是“ /”。 I replaced them but I got the same. 我替换了它们,但我得到了相同的结果。 I don't know what's next! 我不知道接下来会发生什么!
First, you need to parse the original to be an instance of the DateTime
struct. 首先,您需要将原始文件解析为DateTime
结构的实例。 It just holds the date and time data , not any format : 它只保存日期和时间数据 ,而不是任何格式 :
Date_Creation = Date.Parse(noeudEnf.InnerText.ToString)
Then you can format it as a string: 然后,您可以将其格式化为字符串:
SomeString = Date_Creation.ToString("dd/MM/yyyy")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.