.net-core - 未识别为有效的日期时间

标签 .net-core csvhelper

我们使用 CSVHelper 上传带有日期列的 CSV 文件,并在开发机器上工作正常,直到我们将以下问题发布到 Azure 中:

An unhandled exception occurred while processing the request. FormatException: String '13/12/2018' was not recognized as a valid DateTime. System.DateTimeParse.Parse(ReadOnlySpan s, DateTimeFormatInfo dtfi, DateTimeStyles styles)

ReaderException: An unexpected error occurred. CsvHelper.Configuration.ConfigurationFunctions.ReadingExceptionOccurred(CsvHelperException exception)

机器使用的是 dd/MM/yyyy 格式的澳大利亚日期。看起来 Azure 设置为美国格式一。我们如何改变这个?或者如何强制将其纳入 .Net 核心代码配置?

我们还发现,即使我们将日期格式更改为 ISO 日期:yyyy-MM-dd ... 再次在开发上正常运行,但在 Azure 生产中却不行?

有什么想法吗?

最佳答案

修改并解决问题:

var csvReader = new CsvReader(reader2);
csvReader.Configuration.CultureInfo = CultureInfo.GetCultureInfo("en-AU");
var records = csvReader.GetRecords<UploadBatchItem>();

关于.net-core - 未识别为有效的日期时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53907752/

相关文章:

c# - CsvHelper,编写动态变量名(c#)

c# - CsvHelper 在 VisualStudio 2013 中非常慢

c# - 从 URI 查询字符串解析字符串总是返回空值

CSVHelper : How to detect the Delimiter from the given csv file

javascript - 通过ajax下载文件会导致文件损坏

c# - 我可以使用 Microsoft Dotnet CLI 构建 ASP.NET Core Web 应用程序吗?

c# - C# 中的 JSON 字符串到 CSV 和 CSV 到 JSON 的转换

c# - 阅读前修剪值

c# - 如何通过 LINQ 将 TimeSpan 计算转换为 SQL

c# - .net core 和 .net framework 4.6 的 Nuget 包兼容性