4

I'm trying to get a ISO8601 formatted date in the following format yyyy-MM-ddTHH:mm:ss.fffffff zzz to a .csv using CsvHelper.

public System.DateTimeOffset ChangeDT { get; set; }
Map(m => m.ChangeDT).ConvertUsing<string>(row => row.GetField<DateTimeOffset>("ChangeDT").ToString("yyyy-MM-ddTHH:mm:ss.fffffff zzz"));

Although the above code produces:

6/10/2014 12:00:00 AM -05:00

what I'm looking for it to output is:

2014-06-10 12:00:00.1234567 -05:00

What am I doing wrong?

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
Joe R.
  • 123
  • 11
  • Might http://stackoverflow.com/questions/21678385/csvhelper-convertusing-not-changing-output be relevant? (Admittedly it's very old...) – Jon Skeet Jun 13 '14 at 13:51
  • Possibly, but I'm using it for other fields as well, such as converting a string.ToUpper, and that works fine. – Joe R. Jun 13 '14 at 14:02

1 Answers1

5

You can simply provide the "o" format string to the type converter.

Map(m => m.ChangeDT).TypeConverterOption("o");
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575