TimeZoneInfo in .NET Core when hosting on unix nginx
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
When developing applications in .NET Core, handling time zones correctly is essential, especially when hosting on a Unix-based system like those managed by Nginx. This can pose unique challenges due to differences in how time zones are handled across operating systems. In this article, we explore the TimeZoneInfo class in .NET Core, focusing on its usage within Unix environments.
Understanding TimeZoneInfo
TimeZoneInfo is a powerful class that allows developers to work with time zones, providing methods to convert times between different time zones and manage daylight saving time transitions. It is a central piece when you need to deal with applications that are being accessed globally.
Key Properties and Methods
- Properties:
Id: A unique string identifier for the time zone.BaseUtcOffset: The difference between Coordinated Universal Time (UTC) and the time zone.DisplayName: A friendly name for the time zone.SupportsDaylightSavingTime: A Boolean indicating if the time zone supports daylight saving time.
- Methods:
ConvertTime: Converts a time from one time zone to another.FindSystemTimeZoneById: Retrieves a time zone by its identifier.GetSystemTimeZones: Returns a collection of all available time zones on the system.
Hosting on Unix with Nginx
When hosting on Unix-based systems, understanding the environment's time zone specifications is crucial. Unix systems traditionally use the IANA time zone database (also known as tz database or zoneinfo database), which is different from the Windows time zones.
Differences Between Windows and Unix Time Zones
In Windows, time zones are identified by their registry keys, while on Unix, they are recognized using the IANA identifiers. For instance:
- Pacific Standard Time on Windows:
"Pacific Standard Time" - Pacific Standard Time on Unix:
"America/Los_Angeles"
This difference necessitates handling time zones with their exact identifiers to prevent runtime errors.
Example Code
Below is an example code snippet demonstrating how to handle time zones in a .NET Core application running on Unix:
Related reading
- Tomcat How to find out running Tomcat version?
- Tracing versus Logging and how does log4net fit in?
- Tracing XML request/responses with JAX-WS
- Tradeoff between building own distributed system and using kubernetes to deploy my application
- TimeZoneInfo.ConvertTimeToUtc issue
- Tips for optimizing C/.NET programs
- Traefik Forward Authentication in k8s ingress controller
- Training a Neural Network in Python and deploying in C

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.