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. Problem while Parsing DateTime.

Problem while Parsing DateTime.

Scheduled Pinned Locked Moved C#
jsonhelp
5 Posts 4 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.
  • S Offline
    S Offline
    Sunil G 3
    wrote on last edited by
    #1

    Hi, I am collecting OS info using Win32_OperatingSystem(WMI). its one property(InstallDate) which gives Installation Date of the OS, but datetime is in 20091117110355.375000+330 format. I want to convert this into actual DateTime format. Thanks, Sunil G.

    M L A 3 Replies Last reply
    0
    • S Sunil G 3

      Hi, I am collecting OS info using Win32_OperatingSystem(WMI). its one property(InstallDate) which gives Installation Date of the OS, but datetime is in 20091117110355.375000+330 format. I want to convert this into actual DateTime format. Thanks, Sunil G.

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

      Try this...

      DateTime GetMeTheDateAndTime(string s)
      {
      return DateTime.ParseExact(s.Substring(0, 14), "yyyyMMddHHmmss", System.Globalization.CultureInfo.InvarientCulture);
      }

      ...you may wan't to apply some validation thou

      Life goes very fast. Tomorrow, today is already yesterday.

      S 1 Reply Last reply
      0
      • S Sunil G 3

        Hi, I am collecting OS info using Win32_OperatingSystem(WMI). its one property(InstallDate) which gives Installation Date of the OS, but datetime is in 20091117110355.375000+330 format. I want to convert this into actual DateTime format. Thanks, Sunil G.

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        This works for sure, there may be something more compact:

        string s="20091117110355.375000+330";
        DateTime.ParseExact(s.Substring(0,14), "yyyyMMddHHmmss",null);

        :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


        1 Reply Last reply
        0
        • M musefan

          Try this...

          DateTime GetMeTheDateAndTime(string s)
          {
          return DateTime.ParseExact(s.Substring(0, 14), "yyyyMMddHHmmss", System.Globalization.CultureInfo.InvarientCulture);
          }

          ...you may wan't to apply some validation thou

          Life goes very fast. Tomorrow, today is already yesterday.

          S Offline
          S Offline
          Sunil G 3
          wrote on last edited by
          #4

          Thank You Very Much

          1 Reply Last reply
          0
          • S Sunil G 3

            Hi, I am collecting OS info using Win32_OperatingSystem(WMI). its one property(InstallDate) which gives Installation Date of the OS, but datetime is in 20091117110355.375000+330 format. I want to convert this into actual DateTime format. Thanks, Sunil G.

            A Offline
            A Offline
            Alan N
            wrote on last edited by
            #5

            Hi, There is also a .NET class to handle this conversion.

            string dmtfDate = "20091117110355.375000+330";
            DateTime dt = System.Management.ManagementDateTimeConverter.ToDateTime(dmtfDate);

            Alan.

            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