【问题标题】:The time zone ID 'CST' was not found on the local computer在本地计算机上找不到时区 ID“CST”
【发布时间】:2017-06-26 16:26:36
【问题描述】:

我在 MAC 操作系统中创建货件时遇到问题。在 Windows 操作系统中,该网站运行良好。任何帮助将不胜感激

谢谢。

代码:

createOrUpdateShipment: function (shipmentHeader) {


----------

        var tzm= (/\((.*)\)/.exec(new Date().toString())[1]);
        return $http.post('/shipment/CreateOrUpdateShipment?tzm='+tzm, shipmentHeader)
    },

在控制器中

 public ActionResult CreateOrUpdateShipment(ShipmentInfo shipmentInfo, string tzm)
    TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(tzm);
shipmentInfo.ServiceInfo.READYDATETYPE =       TimeZoneInfo.ConvertTime(shipmentInfo.ServiceInfo.READYDATETYPE,tzi);  

当我尝试使用 MAC 操作系统创建货件时出现以下错误

获取错误时区未找到异常。未找到时区 ID“CST”


【问题讨论】:

  • 与其依赖可能因语言和平台而异的命名时区,我强烈建议在 .NET 中使用 DateTimeOffset 或像 NodaTime 这样的包来处理本地化的日期和时间。
  • 这个问题已经回答了吗?

标签: c# angularjs


【解决方案1】:

.NET 中的时区由它们的全名而不是它们的缩写来标识。您正在拨打FindSystemTimeZoneById 的电话。此 API 需要 "Central Standard Time",而不是 "CST"

我猜你的 Mac 客户端正在发送 tzm=CST,而你的 Windows 客户端正在发送 tzm=Central+Standard+Time。您的服务器仅在客户端说明时才有效。

【讨论】:

猜你喜欢
  • 2020-12-06
  • 1970-01-01
  • 2022-10-13
  • 2021-11-30
  • 2016-11-10
  • 1970-01-01
  • 2016-08-05
  • 2014-06-05
  • 2012-09-01
相关资源
最近更新 更多