DateTime Formatting on Azure hosted site

人盡茶涼 提交于 2020-01-04 05:44:11

问题


so my tech stack is: asp.net core 1.1 hosted on Azure using CSV Helper to read CSVs into a SQL database (in azure).

ok so the problem i'm facing is when i'm using CSV helper locally its all fine, the date format is reading it as per the CSV file into the format i want (dd/mm/yyyy i'm in sydney).

when i import a file hosted on the azure site.. my date formats are screwed (they are converting to the US).

how do i go about importing those dates correctly using CSV Helper?

in my startup.cs i have the following:

    //Currently only supports en-AU culture. This forces datetime and number formats to the en-AU culture regardless of local culture
    var auCulture = new CultureInfo("en-AU");
    var supportedCultures = new[] { auCulture };
    services.Configure<RequestLocalizationOptions>(options =>
    {
        options.DefaultRequestCulture = new RequestCulture(auCulture, auCulture);
        options.SupportedCultures = supportedCultures;
        options.SupportedUICultures = supportedCultures;
    });

and i'm using UTC across the site, but since these datetimes are coming from CSVHelper, that seems to be screwing up my format.

any ideas?

cheers,


回答1:


If you want to make sure CsvHelper always uses one particular culture, you can set it explicitly:

csv.Configuration.CultureInfo = auCulture;

You should bear in mind, however, that a DateTime doesn't "store" a format - so once you've parsed the value in the CSV file, you've just got a DateTime value... you may well need to explicitly control any later formatting of that value for the UI or other output.



来源:https://stackoverflow.com/questions/42139087/datetime-formatting-on-azure-hosted-site

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!