在 unix (nginx) 上托管时 .NET Core 中的 TimeZoneInfo [英] TimeZoneInfo in .NET Core when hosting on unix (nginx)
问题描述
例如,当我尝试执行以下操作时.
For example, when I try to do the following.
TimeZoneInfo.FindSystemTimeZoneById("Central European Standard Time")
我收到错误消息,TimeZone
在本地计算机上不可用.当我在本地运行它时,它可以工作,但我在 Windows 上运行它.部署后,它在 Nginx 中的 Unix 机器上运行.我可以看到 FindSystemTimeZoneById
在 Unix 中查找错误的文件夹.有什么办法可以让这个工作吗?
I get the error, that the TimeZone
is not available on the local computer. When I run this locally it works, but there I run it on windows. When deployed it runs on a Unix machine in Nginx. I can see that FindSystemTimeZoneById
is looking in the wrong folder when it comes to Unix. Is there any way to make this work?
推荐答案
.Net Core 使用系统时区.不幸的是,Windows 和 Linux 有不同的时区系统.现在你有两种方法:
.Net Core using system timezone. Unfortunately Windows and Linux have different timezone system. Now you have two ways:
- 使用其他(和通用的)时区限制,例如 Noda time
- 翻译Windows 和 IANA 时区之间,例如使用 TimeZoneConverter 微型库.
- Use other (and universal) impementation of timezone like Noda time
- Translate between Windows and IANA time zones, e.g. using the TimeZoneConverter micro-library.
这篇关于在 unix (nginx) 上托管时 .NET Core 中的 TimeZoneInfo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!