1

I need to parse date times of the following format:

yyyyMMdd'T'(time elapsed since 12 AM) Time Zone

Here are two examples of what I have been given to parse:

20160301T162327.259 GMT
20160301T165900.541 GMT

Is this a common known DateTime format? I could not find it in any of the Standard Date and Time Format Strings. The following SO topics will help if I need to write code to parse it (2,3), but I didn't want to reinvent the wheel.

Community
  • 1
  • 1
Eric Scherrer
  • 3,328
  • 1
  • 19
  • 34
  • 1
    that doesn't look like a standard. – Daniel A. White Mar 01 '16 at 18:33
  • Do you have a precise definition of "time zone" here? (Generally, time zone abbreviations should be avoided; for a single date/time, a UTC offset *may* be okay. If you only need to accept "GMT" that's simpler...) – Jon Skeet Mar 01 '16 at 18:33
  • This looks essentially like ISO-8601 (without delimiters) with a non-standard time-zone specifier. – Joey Mar 01 '16 at 18:34
  • 3
    @DanielA.White: Before the time zone part, it's compact ISO-8601. – Jon Skeet Mar 01 '16 at 18:34
  • From the above commentary, I think you have answered my question. This must be some proprietary format. I will reach out to them and see if they can change to a standard format or at least confirm that this will always be UTC and I can ignore the time zone part. – Eric Scherrer Mar 01 '16 at 18:45
  • I'll let this marinate for a few days and unless someone recognizes it I will delete from SO as I don't see that it adds any value. – Eric Scherrer Mar 01 '16 at 18:51

1 Answers1

2

You can use custom format future when parsing to DateTime:

using System;
using System.Globalization;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string text = "20160301T162327.259 GMT";
            string pattern = "yyyyMMddTHHmmss.fff GMT";
            DateTime dateTime;
            if (DateTime.TryParseExact(text, pattern, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
            {
                // DataTime is parsed
            }
            else
            {
                // Invalid string
            }
        }
    }
}
  • Thanks, that is pretty much what I did. As Jon Skeet mentions above it is compact ISO-8607, with what seems to me an uncommon time format. I have an email out to the providers of these dates if I can safely ignore then GMT. Thanks again. – Eric Scherrer Mar 02 '16 at 15:22