Search code examples
c#datetimeiso8601datetimeoffsetcsvhelper

Forcing ISO 8601 with CSVHelper


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?


Solution

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

    Map(m => m.ChangeDT).TypeConverterOption("o");