C# – Get a time zone’s display name with the current date’s UTC offset

A time zone’s UTC offset can change based on the time of year due to daylight savings time. One problem with the TimeZoneInfo class is that TimeZoneInfo.DisplayName always shows the base UTC offset, even if the current date is in daylight savings time. This may be confusing to users (and this is the same thing … Read more

C# – How to use TimeZoneInfo

Time zones are complicated and their rules can change, so it makes sense to use a library when you’re dealing with them. One option in .NET is to use the built-in TimeZoneInfo class. Here’s an example of using TimeZoneInfo to get the local system’s time zone: This outputs: Note: The display name always show the … Read more

C# – Get the current date and time

Here’s an example of how to get the current date/time: This outputs the current local date/time: Note: By default, it uses the current culture’s format (from the OS). This is showing the US date format – MM/dd/yyyy. DateTime.Now is the local date/time from the system where the code is executing. Keep that in mind if … Read more