UTC DateTime format using FileHelpers

I have a record that I write to a CSV file using FileHelpers. I want the DateTime fields of the structure to be written out as UTC date. I currently have the following formatter:

[FieldConverter(ConverterKind.Date, "yyyy-MM-dd")]   

What do I need to do to display the UTC date?

+3
source share
3 answers

Doc says:

You can check all supported string formats; check MSDN docs for DateTime.ParseExact

So, according to http://msdn.microsoft.com/en-us/library/az4se3k1.aspx

[FieldConverter (ConverterKind.Date, "u")]

"u" = > "yyyy '-' MM '-' dd HH ':' mm ':' ss'Z '" utc,

DateTime.ToUniversalTime .

Edit - :

[FieldConverter(ConverterKind.Date, "ddMMyyyy" )]
public DateTime ShippedDate;

temp ShippedDateUTC:

public DateTime ShippedDate;

[FieldConverter(ConverterKind.Date, "ddMMyyyy" )]
public DateTime ShippedDateUTC {
  get{ return ShippedDate.ToUniversalTime();}
}
+3

, . :

public class OutputRecord
{
    [FieldConverter(ConverterKind.Date, "ddMMyyyy" )]
    private DateTime dateInUtc:

    public void SetDate(DateTime date)
    {
        dateInUtc = date.ToUniversalTime();
    }

}

http://www.filehelpers.com/example_customconv.html

+3

ToUniversalTime() DateTime

, ConverterKind.Date DateTime,

[FieldConverter(ConverterKind.Date.ToUniversalTime(), "yyyy-MM-dd")]
+1

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


All Articles