Search code examples
c#.netdatetimedatetime-formatreuters

Convert to DateTime "05:10:15D+0"


I'm having trouble Converting "05:10:15D+0" to DateTime. Reuters has the datatype as "bftime" and time is in GMT/UTC.

I don't want to substring it as I have Multiple Market Data Providers which send this value as only Date if the markets have not opened up.

Following is the way I'm trying to convert.ToDateTime

MDLastTick =  Convert.ToDateTime(LastTick);

Exception:

The string was not recognized as a valid DateTime. There is a unknown word starting at index 8.


Solution

  • You could use this regexp to just grab out the time component: \d{1,2}:\d{1,2}:\d{1,2} (Or just use the first 8 characters as a substring) - and then datetime.parse the matching time. You know it's always UTC so you can ignore the D+0.

    This is however just a time, not a datetime.