azure - Azure DevOps 中的字符串未被识别为有效的日期时间错误

标签 azure datetime datetime-format

当我们从 Azure DevOps 构建管道构建 Xamarin 应用程序时,我收到上述错误。

我们的 Xamarin 应用使用 ASP.NET Web API 服务,该服务接收日期作为参数。日期作为序列化字符串传递。该服务使用 DateTime.Parse() 函数将字符串转换回 DateTime,如下所示。

CultureInfo cultureinfo = new CultureInfo("en-GB");
DateTime startdate = DateTime.Parse(strstartdate, cultureinfo);

我希望所有日期都采用 GB 格式,因为这就是它们的处理和存储方式。

当单元测试从我们的开发机器本地调用服务时,它们全部通过。但当从 Azure DevOps 执行时,它们会失败。我怀疑 Azure DevOps 以美国格式发送日期,然后当 DateTime.Parse() 函数尝试转换它们时会中断。

如何解决这个问题?我希望 Azure DevOps 以 GB 格式发送日期。

最佳答案

设置CultureInfo.CurrentCulture Property使单元测试项目成为 en-GB

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");

关于azure - Azure DevOps 中的字符串未被识别为有效的日期时间错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56663616/

相关文章:

azure - 由于证书不受信任,无法从 Azure SF 连接到外部 https

c# - 无法通过 Azure AD B2C 属性中的 Graph API 创建用户不存在

Azure Web App .net core OpenID redirect_uri 问题

使用 WHERE 子句的 Android sql 查询

php - 在 PHP 中转换日期格式(但这是什么格式?)

html - Django 模板转换 datetime-local 格式

node.js - 使用特定 Node 版本通过 Azure 部署静态 Web 应用程序

python - 如何在 Python 中有效地将字符串类型的数据框列转换为日期时间?

android - 乔达和安卓 : How to format a date for display in the user's locale?

c# - 将 Xamarin Forms 中的 DateTime 格式化为设备格式字符串