Parse Datetime string

前端 未结 4 1721
被撕碎了的回忆
被撕碎了的回忆 2021-01-23 09:16

I\'m trying to convert the following string to datetime. I\'ve searched high and low and can\'t find the exact formats string and I don\'t want to resort to parsing it manually.

相关标签:
4条回答
  • 2021-01-23 09:23

    Have you tried this:

    DateTime.ParseExact("20110828T134108+0100", "yyyyMMdd'T'HHmmsszzzz", CultureInfo.InvariantCulture);
    
    0 讨论(0)
  • 2021-01-23 09:28

    try this format: "yyyyMMdd'T'HHmmss"

    0 讨论(0)
  • 2021-01-23 09:30

    The documentation on the format string is here: http://msdn.microsoft.com/en-us/library/8kb3ffffd4.aspx

    That should get you started. :)

    0 讨论(0)
  • 2021-01-23 09:43

    Have you tried this?

    var date = DateTime.ParseExact( dateString
       ,"yyyyMMdd\THHmmsszzz"
       ,CultureInfo.InvariantCulture 
       );  
    

    From MSDN:

    If format is a custom format pattern that does not include date or time separators (such as "yyyyMMdd HHmm"), use the invariant culture for the provider parameter and the widest form of each custom format specifier. For example, if you want to specify hours in the format pattern, specify the wider form, "HH", instead of the narrower form, "H".

    0 讨论(0)
提交回复
热议问题