Forcing ISO 8601 with CSVHelper

I am trying to get the formatted date of ISO8601 in the following format yyyy-MM-ddTHH:mm:ss.fffffff zzzbefore .csvusing 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 gives:

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

what i'm looking for output:

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

What am I doing wrong?

+4
source share
1 answer

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

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

Source: https://habr.com/ru/post/1544487/


All Articles