Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
I have been working on this application that reads a file and gets infromation on software. The output is 2011-10-20T20:49:59-0400 and I need to get the string to look like this Oct 20, 2011 20:49:59

I can split the 2 at the t with the code below but i cant get the output i want and need some help.

VB
Dim str As String
Dim strArr() As String
Dim count As Integer
str = INSTDATE
strArr = str.Split("T")
For count = 0 To strArr.Length - 2
    INSTDATE = (strArr(count))
Next
Posted

Hello

try this:

VB
Dim str As String = Nothing
Dim strArr As String() = Nothing
str = "2011-10-20T20:49:59-0400"
strArr = str.Split("T")

Dim converted As String = String.Format("{0} {1}", DateTime.Parse(strArr(0)).ToString("MMMM-dd-yyyy"), strArr(1))


Of course, it's better to use TryParse instead of Pars and handle unknown formats.
 
Share this answer
 
v5
Use this code:

INSTDATE.ToString("MMM dd,yyyy HH:mm:ss")
 
Share this answer
 
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 24-Mar-12 18:15pm    
In principle, enough, a 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900