Trying to convert a string to date time format in vb.net 2005

ⅰ亾dé卋堺 提交于 2019-12-12 16:53:05

问题


I can't seem to be able to convert a string that contains date value of "100714 0700" (2010-07-14 7am) to a date format in vb.net 2005

When I attempt to do:

        Dim provider As Globalization.CultureInfo = Globalization.CultureInfo.InvariantCulture
        strPickupDateTime = DateTime.ParseExact(txtPickupDate.Text, "yymmdd", provider)  

I get back "1/14/2010 12:07:00 AM"
How can I get a value of "2010-07-14 7:00" ?


回答1:


Here is another link from here on SO that shows how to do this in C#

Convert String to Date in .NET if my incoming date format is in YYYYMMDD

In your case you probably also want add the time format:

  string s = "100714 0700";
  DateTime d = DateTime.ParseExact(s, "yyMMdd hhmm", CultureInfo.InvariantCulture);



回答2:


Sorry, I read the question to quickly last time, hmmm have you tried something like strPickupDateTime = DateTime.ParseExact(txtPickupDate.Text, "yy" & "-" & "-" & "mm" & "-" & "dd", provider)



来源:https://stackoverflow.com/questions/4156614/trying-to-convert-a-string-to-date-time-format-in-vb-net-2005

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!