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. dateTime parser

dateTime parser

Scheduled Pinned Locked Moved C#
question
2 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.
  • R Offline
    R Offline
    Rob Tomson
    wrote on last edited by
    #1

    i've converted a dateTime to a string using the following: [_datetime_].Start.ToString("yyyyMMdd'T'HHmmss"); let's say i've saved this out to a text file and now i'm reading the information back in as a string. how would i then convert this dateTime string back to a System.DateTime object? thanks, Rob Tomson -- There are 10 kinds of people. Those who understand binary and those who don't.

    J 1 Reply Last reply
    0
    • R Rob Tomson

      i've converted a dateTime to a string using the following: [_datetime_].Start.ToString("yyyyMMdd'T'HHmmss"); let's say i've saved this out to a text file and now i'm reading the information back in as a string. how would i then convert this dateTime string back to a System.DateTime object? thanks, Rob Tomson -- There are 10 kinds of people. Those who understand binary and those who don't.

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      If you use the built-in format provider with the switch 's' you get aery similar format to yours above and you can use the parse static method on a DateTime...eg: string s = DateTime.Now.ToString("s"); Console.WriteLine(s); DateTime parsedDateTime = DateTime.Parse(s); Console.WriteLine(parsedDateTime); the "S" switch is defined as this format in the Docs: 2002-01-03T00:00:00 yyyy'-'MM'-'dd'T'HH':'mm':'ss (SortableDateTimePattern) If you really want your own format then you can write your own class which implements IFormatProvider, or inherits from DateTimeFormatInfo. DateTimeFormatInfo[^]

      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