Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Converting a date format

Converting a date format

Scheduled Pinned Locked Moved C#
questioncsharp
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MarkB123
    wrote on last edited by
    #1

    Hi, I have date data supplied as a string in the following format... "Mon Sep 9 00:00:00 UTC 0100 2013". Firstly, what is this format? Secondly, how can I use C# to convert it and stire it in a DateTime variable? I've tried... DateTime dt = Convert.ToDateTime("Mon Sep 9 00:00:00 UTC 0100 2013"); but this blows up :( Many Thanks.

    M V 2 Replies Last reply
    0
    • M MarkB123

      Hi, I have date data supplied as a string in the following format... "Mon Sep 9 00:00:00 UTC 0100 2013". Firstly, what is this format? Secondly, how can I use C# to convert it and stire it in a DateTime variable? I've tried... DateTime dt = Convert.ToDateTime("Mon Sep 9 00:00:00 UTC 0100 2013"); but this blows up :( Many Thanks.

      M Offline
      M Offline
      MarkB123
      wrote on last edited by
      #2

      Also tried... DateTime dt = DateTime.ParseExact("Mon Sep 9 00:00:00 UTC 0100 2013", "ddd MMM dd HH:mm:ss K yyyy", CultureInfo.InvariantCulture); Doesn't work either...

      1 Reply Last reply
      0
      • M MarkB123

        Hi, I have date data supplied as a string in the following format... "Mon Sep 9 00:00:00 UTC 0100 2013". Firstly, what is this format? Secondly, how can I use C# to convert it and stire it in a DateTime variable? I've tried... DateTime dt = Convert.ToDateTime("Mon Sep 9 00:00:00 UTC 0100 2013"); but this blows up :( Many Thanks.

        V Offline
        V Offline
        V 0
        wrote on last edited by
        #3

        See here[^] it lists, d, D, f, F, g, G, M, m, O, o, R, r, S, t, T, u, U, y, Y as valid format strings, and below the table it says : Any other single character unknown specifier. Throws a run-time FormatException. In my case it says: String was not recognized as a valid DateTime. try to remove the K specification along with the 0100...

        V.
        (MQOTD Rules and previous Solutions )

        M 1 Reply Last reply
        0
        • V V 0

          See here[^] it lists, d, D, f, F, g, G, M, m, O, o, R, r, S, t, T, u, U, y, Y as valid format strings, and below the table it says : Any other single character unknown specifier. Throws a run-time FormatException. In my case it says: String was not recognized as a valid DateTime. try to remove the K specification along with the 0100...

          V.
          (MQOTD Rules and previous Solutions )

          M Offline
          M Offline
          MarkB123
          wrote on last edited by
          #4

          Thanks for the reply. I can't get it to work as a UTC. If I change it to UTC+ by adding the plus sign in to replace the space directly after the UTC on the fly then parse I can get it to work... string strStart = "Mon Sep 9 00:00:00 UTC 0100 2013"; strStart = strStart.Replace("UTC ", "UTC+"); DateTime dtStart = DateTime.ParseExact(strStart, "ddd MMM d HH:mm:ss UTCzzzz yyyy", CultureInfo.InvariantCulture); This works!

          V 1 Reply Last reply
          0
          • M MarkB123

            Thanks for the reply. I can't get it to work as a UTC. If I change it to UTC+ by adding the plus sign in to replace the space directly after the UTC on the fly then parse I can get it to work... string strStart = "Mon Sep 9 00:00:00 UTC 0100 2013"; strStart = strStart.Replace("UTC ", "UTC+"); DateTime dtStart = DateTime.ParseExact(strStart, "ddd MMM d HH:mm:ss UTCzzzz yyyy", CultureInfo.InvariantCulture); This works!

            V Offline
            V Offline
            V 0
            wrote on last edited by
            #5

            :thumbsup:

            V.
            (MQOTD Rules and previous Solutions )

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups