在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时间
- 翻译 在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屋!