Converting DXL timestamp to C# DateTime

totally messed up with Lotus Notes DXL timestamp format... Given is a timestamp of an exported DXL from a Lotus Notes document, which looks like that:

20141104T132939,49+01

Trying to get the format working with DateTime.ParseExact, like:

DateTime.ParseExact(dateStr.Substring(0, 13), "yyyyMMddThhmm", System.Globalization.CultureInfo.InvariantCulture).ToString("dd.MM.yyyy hh:mm");

But with no luck >>> System.FormatException "no valid DateTime format".

Can C# handle the above timestamp as it is?

Jon Skeet
people
quotationmark

The problem is your text format - you've used hh which is the 12-hour clock, but you've got a value of 13. You want HH, which is the 24-hour clock. I'd also recommend quoting the T as you just want the literal T character, and also taking the following two characters for the second:

DateTime dateTime = DateTime.ParseExact(
    dateStr.Substring(0, 15),
    "yyyyMMdd'T'HHmmss",
    CultureInfo.InvariantCulture);

I would then suggest keeping it as a DateTime for as long as you can, only converting back to a string where you actually need to display this to a client.

people

See more on this question at Stackoverflow