Azure托管网站上的DateTime格式 [英] DateTime Formatting on Azure hosted site

查看:81
本文介绍了Azure托管网站上的DateTime格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我的技术栈是:在Azure上托管的asp.net core 1.1使用CSV Helper将CSV读入SQL数据库(天蓝色).

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).

好的,所以我要面对的问题是当我在本地使用CSV helper时,日期格式正在按照CSV文件将其读取为我想要的格式(dd/mm/yyyy,我在悉尼).

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).

当我导入azure网站上托管的文件时..我的日期格式被搞砸了(它们正在转换为美国).

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

如何使用CSV Helper正确导入这些日期?

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

在我的startup.cs中,我具有以下内容:

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;
    });

并且我在整个网站上都使用UTC,但是由于这些日期时间来自CSVHelper,因此这似乎弄糟了我的格式.

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

有什么想法吗?

欢呼

推荐答案

如果要确保 CsvHelper 始终使用一种特定的区域性,则可以对其进行显式设置:

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

csv.Configuration.CultureInfo = auCulture;

但是,请记住, DateTime 不会存储"格式-因此,一旦您在CSV文件中解析了值,就得到了 DateTime 值...您可能需要显式控制UI或其他输出的该值的任何以后的格式.

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.

这篇关于Azure托管网站上的DateTime格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆