未识别为有效的日期时间

Not recognized as a valid DateTime

我们使用 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>();