Results 1 to 3 of 3

Thread: [RESOLVED] [2008] Parse XML style date and time

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Manchester, England
    Posts
    255

    Resolved [RESOLVED] [2008] Parse XML style date and time

    Hello,
    I've been struggling with this all afternoon, and everything I find on Google seems to talk about converting dates and times TO the format I've already got.
    I have an XML file which has recorded a date and time of:

    2009-03-28T16:24:22+00:00

    What I want to know is how I convert it to dd/MM/yyyy.

    In my despiration, I've started working with substrings to break it up and re-assemble it again, but there has got to be a better way.

    One of the latest things I've tried is:

    Code:
    strDate = strDate.Substring(0, 10)
    Dim dteDate As DateTime = DateTime.ParseExact(strDate, "yyyy-MM-dd", New Globalization.CultureInfo("en-GB"))
    ... but this complains that The DateTime represented by the string is not supported in calendar System.Globalization.GregorianCalendar.

    Convert.ToDateTime(strDate) doesn't seem to want to play either.
    At home - VB.NET 2005/2008 Express, Visual Web Developer 2005 Express
    At work - VS 2008 Standard (VB)
    .NET 2.0/3.5


    Visual Studio Express Learning Centre | How do I videos | MSDN VB Express Forum | MSDN VB Developer Centre

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2008] Parse XML style date and time

    Try this
    Code:
    Dim s As String = "2009-03-28T16:24:22+00:00"
    Dim d As Date = Date.ParseExact(s, "yyyy-MM-dd'T'HH:mm:sszzz", Nothing)
    MsgBox(d.ToString)

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Manchester, England
    Posts
    255

    Re: [2008] Parse XML style date and time

    Many thanks.
    At home - VB.NET 2005/2008 Express, Visual Web Developer 2005 Express
    At work - VS 2008 Standard (VB)
    .NET 2.0/3.5


    Visual Studio Express Learning Centre | How do I videos | MSDN VB Express Forum | MSDN VB Developer Centre

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width