跳到正文
Skillpedia
通用编程40k · #7180

dotnet-timezone

它能做什么

这个工具可以帮助程序员在 C#(.NET)代码中处理时区。它提供了一些信息,告诉你如何在不同地点之间转换时间、理解夏令时,以及确保代码在不同操作系统上都能正确运行。

适用场景

  • ✓当你需要查询某个城市所在的时区时。
  • ✓当你需要在 UTC 和本地时间之间进行转换时。
  • ✓当你想确保代码在 Windows 和 Linux 电脑上都能正确运行时。

技能链接

https://github.com/github/awesome-copilot/blob/main/skills/dotnet-timezone/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/github/awesome-copilot/blob/main/skills/dotnet-timezone/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“东京是什么时区?请给我一个 C# 代码示例,把当前时间从 UTC 转换为东京时间。”

每周 5 个新技能,1 分钟读完。

工作原理

这个工具会查找已知的时区标识,并调用 .NET 库来获取正确的信息。它可以根据你的需求生成可以直接使用的代码片段,无论是简单的时间转换,还是复杂的日程安排。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

.NET Timezone

Resolve timezone questions for .NET and C# code with production-safe guidance and copy-paste-ready snippets.

Start With The Right Path

Identify the request type first:

  • Address or location lookup
  • Timezone ID lookup
  • UTC/local conversion
  • Cross-platform timezone compatibility
  • Scheduling or DST handling
  • API or persistence design

If the library is unclear, default to TimeZoneConverter for cross-platform work. If the scenario involves recurring schedules or strict DST rules, prefer NodaTime.

Resolve Addresses And Locations

If the user provides an address, city, region, country, or document containing place names:

  1. Extract each location from the input.
  2. Read references/timezone-index.md for common Windows and IANA mappings.
  3. If the exact location is not listed, infer the correct IANA zone from geography, then map it to the Windows ID.
  4. Return both IDs and a ready-to-use C# example.

For each resolved location, provide:

Location: <resolved place>
Windows ID: <windows id>
IANA ID: <iana id>
UTC offset: <standard offset and DST offset when relevant>
DST: <yes/no>

Then include a cross-platform snippet like:

using TimeZoneConverter;

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

If multiple locations are present, include one block per location and then a combined multi-timezone snippet.

If a location is ambiguous, list the possible timezone matches and ask the user to choose the correct one.

Look Up Timezone IDs

Use references/timezone-index.md for Windows to IANA mappings.

Always provide both formats:

  • Windows ID for TimeZoneInfo.FindSystemTimeZoneById() on Windows
  • IANA ID for Linux, containers, NodaTime, and TimeZoneConverter

Generate Code

Use references/code-patterns.md and pick the smallest pattern that fits:

  • Pattern 1: TimeZoneInfo for Windows-only code
  • Pattern 2: TimeZoneConverter for cross-platform conversion
  • Pattern 3: NodaTime for strict timezone arithmetic and DST-sensitive scheduling
  • Pattern 4: DateTimeOffset for APIs and data transfer
  • Pattern 5: ASP.NET Core persistence and presentation
  • Pattern 6: recurring jobs and schedulers
  • Pattern 7: ambiguous and invalid DST timestamps

Always include package guidance when recommending third-party libraries.

Warn About Common Pitfalls

Mention the relevant warning when applicable:

  • TimeZoneInfo.FindSystemTimeZoneById() is platform-specific for timezone IDs.
  • Avoid storing DateTime.Now in databases; store UTC instead.
  • Treat DateTimeKind.Unspecified as a bug risk unless it is deliberate input.
  • DST transitions can skip or repeat local times.
  • Azure Windows and Azure Linux environments may expect different timezone ID formats.

Response Shape

For address and location requests:

  1. Return the resolved timezone block for each location.
  2. State the recommended implementation in one sentence.
  3. Include a copy-paste-ready C# snippet.

For code and architecture requests:

  1. State the recommended approach in one sentence.
  2. Provide the timezone IDs if relevant.
  3. Include the minimal working code snippet.
  4. Mention the package requirement if needed.
  5. Add one pitfall warning if it matters.

Keep responses concise and code-first.

References

  • references/timezone-index.md: common Windows and IANA timezone mappings
  • references/code-patterns.md: ready-to-use .NET timezone patterns
常见问题

什么是 UTC?

UTC(协调世界时)是全球调节时钟所依据的主要时间标准。它类似于“格林尼治标准时间”(GMT),但精度更高。

什么是夏令时(DST)?

夏令时是指在某个时段(通常是春季)把时钟拨快,以便更充分地利用日照。并不是所有地区都实行夏令时。

为什么我需要在代码中关注时区?

如果你的应用处理的日期和时间来自不同地区(甚至只是你自己所在地区的时间),那么使用正确的时区至关重要,可以避免错误,尤其是在安排日程或向不同地区的用户显示信息时。

详情

作者的原始描述

.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.

repo: github/awesome-copilot

热度

GitHub 星标
40k
排名
#7180
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能