All skills
github avatar

/dotnet-timezone

@b3de201 official
by githubgithub/awesome-copilot40k stars
5,040

.NET timezone handling guidance for C# applications. Use when working with TimeZoneInfo, DateTimeOffset, NodaTime, UTC conversion, daylight saving time, scheduling across timezones, cross-platform Windows/IANA timezone IDs, or when a .NET user needs the timezone for a city, address, region, or country and copy-paste-ready C# code.

Use this Skill: https://skilld.dev/gh/github/awesome-copilot/dotnet-timezone

This session only. Nothing lands on disk.

referencescode-patterns.md

≈1.1k tokens on demand. Your agent reads this file only when SKILL.md points to it.

.NET Timezone Code Patterns

Pattern 1: Basic TimeZoneInfo

Use this only when the application is Windows-only and Windows timezone IDs are acceptable.

DateTime utcNow = DateTime.UtcNow;
TimeZoneInfo sriLankaTz = TimeZoneInfo.FindSystemTimeZoneById("Sri Lanka Standard Time");
DateTime localTime = TimeZoneInfo.ConvertTimeFromUtc(utcNow, sriLankaTz);

DateTime backToUtc = TimeZoneInfo.ConvertTimeToUtc(localTime, sriLankaTz);

TimeZoneInfo tokyoTz = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time");
DateTime tokyoTime = TimeZoneInfo.ConvertTime(localTime, sriLankaTz, tokyoTz);

Use TimeZoneConverter or NodaTime instead for Linux, containers, or mixed environments.

Pattern 2: Cross-Platform With TimeZoneConverter

Recommended default for most .NET apps that run across Windows and Linux.

<PackageReference Include="TimeZoneConverter" Version="6.*" />
using TimeZoneConverter;

TimeZoneInfo tz = TZConvert.GetTimeZoneInfo("Asia/Colombo");
DateTime converted = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, tz);

This also accepts Windows IDs:

TimeZoneInfo tz = TZConvert.GetTimeZoneInfo("Sri Lanka Standard Time");

Pattern 3: NodaTime

Use this for strict timezone arithmetic, recurring schedules, or DST edge cases where correctness matters more than minimal dependencies.

<PackageReference Include="NodaTime" Version="3.*" />
using NodaTime;

DateTimeZone colomboZone = DateTimeZoneProviders.Tzdb["Asia/Colombo"];
Instant now = SystemClock.Instance.GetCurrentInstant();
ZonedDateTime colomboTime = now.InZone(colomboZone);

DateTimeZone tokyoZone = DateTimeZoneProviders.Tzdb["Asia/Tokyo"];
ZonedDateTime tokyoTime = colomboTime.WithZone(tokyoZone);

LocalDateTime localDt = new LocalDateTime(2024, 6, 15, 14, 30, 0);
ZonedDateTime zoned = colomboZone.AtStrictly(localDt);
Instant utcInstant = zoned.ToInstant();

Pattern 4: DateTimeOffset For APIs

Prefer DateTimeOffset for values crossing service or process boundaries.

using TimeZoneConverter;

DateTimeOffset utcNow = DateTimeOffset.UtcNow;
TimeZoneInfo tz = TZConvert.GetTimeZoneInfo("Asia/Colombo");
DateTimeOffset colomboTime = TimeZoneInfo.ConvertTime(utcNow, tz);

Pattern 5: ASP.NET Core Persistence And Presentation

Store UTC, convert at the edges.

using TimeZoneConverter;

entity.CreatedAtUtc = DateTime.UtcNow;

public DateTimeOffset ToUserTime(DateTime utc, string userIanaTimezone)
{
    var tz = TZConvert.GetTimeZoneInfo(userIanaTimezone);
    return TimeZoneInfo.ConvertTimeFromUtc(utc, tz);
}

Pattern 6: Scheduling And Recurring Jobs

Translate a user-facing local time to UTC before scheduling.

using TimeZoneConverter;

TimeZoneInfo tz = TZConvert.GetTimeZoneInfo("Asia/Colombo");
DateTime scheduledLocal = new DateTime(2024, 12, 1, 9, 0, 0, DateTimeKind.Unspecified);
DateTime scheduledUtc = TimeZoneInfo.ConvertTimeToUtc(scheduledLocal, tz);

With Hangfire:

RecurringJob.AddOrUpdate(
    "morning-job",
    () => DoWork(),
    "0 9 * * *",
    new RecurringJobOptions { TimeZone = tz });

Pattern 7: Ambiguous And Invalid DST Times

Check for repeated or skipped local timestamps when the timezone observes daylight saving time.

using TimeZoneConverter;

TimeZoneInfo tz = TZConvert.GetTimeZoneInfo("America/New_York");
DateTime localTime = new DateTime(2024, 11, 3, 1, 30, 0);

if (tz.IsAmbiguousTime(localTime))
{
    var offsets = tz.GetAmbiguousTimeOffsets(localTime);
    var standardOffset = offsets.Min();
    var dto = new DateTimeOffset(localTime, standardOffset);
}

if (tz.IsInvalidTime(localTime))
{
    localTime = localTime.AddHours(1);
}

Common Mistakes

Wrong Better
DateTime.Now in server code DateTime.UtcNow
Storing local timestamps in the database Store UTC and convert for display
Hardcoding offsets such as +05:30 Use timezone IDs
Using FindSystemTimeZoneById("Asia/Colombo") on Windows Use TZConvert.GetTimeZoneInfo("Asia/Colombo")
Comparing local DateTime values from different zones Compare UTC or use DateTimeOffset
Creating DateTime without intentional kind semantics Use Utc, Local, or deliberate Unspecified

Decision Guide

  • Use TimeZoneInfo only for Windows-only code with Windows IDs.
  • Use TimeZoneConverter for most cross-platform applications.
  • Use NodaTime when DST arithmetic or calendaring accuracy is central.
  • Use DateTimeOffset for APIs and serialized timestamps.

Source: SKILL.md on GitHub

No alerts16d4 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    The skill provides guidance for .NET timezone handling and is generally safe. It identifies standard external dependencies and has a minor surface for indirect prompt injection when processing user-provided location data to generate code snippets.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at b3de201. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated 6 months ago
  • dotnet
  • csharp
  • timezone
  • timezoneinfo
  • nodatime
  • timezonconverter
  • datetimeoffset
  • dst
  • scheduling

README badge

README badge for github/awesome-copilot/dotnet-timezone

Provides timezone ID lookups, UTC/local conversions, and copy-paste C# code for .NET applications using TimeZoneInfo, TimeZoneConverter, or NodaTime. Handles address-to-timezone resolution, cross-platform Windows/IANA ID mapping, daylight saving time edge cases, and scheduling scenarios.

Generated from the current SKILL.md.

Does this skill work with NodaTime?
Yes. The skill recommends NodaTime for strict timezone arithmetic and DST-sensitive scheduling, and includes code patterns for it in the references.
Can this skill resolve a timezone from a city name or address?
Yes. It extracts locations from input, looks them up in the timezone index, and returns both Windows and IANA timezone IDs with UTC offsets and a ready-to-use C# snippet.
Does this handle cross-platform timezone compatibility?
Yes. It defaults to TimeZoneConverter for cross-platform work and provides both Windows and IANA timezone ID formats to handle Windows, Linux, and container environments.
What should I use for storing dates in a database?
Always store UTC in databases, not local time or DateTime.Now. The skill warns against this common pitfall.
Does this cover daylight saving time edge cases?
Yes. It includes guidance on DST transitions that can skip or repeat local times, and recommends NodaTime or specific code patterns for handling ambiguous and invalid DST timestamps.

Generated from the current SKILL.md. These answers refresh after source changes.