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。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 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:
- Extract each location from the input.
- Read
references/timezone-index.mdfor common Windows and IANA mappings. - If the exact location is not listed, infer the correct IANA zone from geography, then map it to the Windows ID.
- 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, andTimeZoneConverter
Generate Code
Use references/code-patterns.md and pick the smallest pattern that fits:
- Pattern 1:
TimeZoneInfofor Windows-only code - Pattern 2:
TimeZoneConverterfor cross-platform conversion - Pattern 3:
NodaTimefor strict timezone arithmetic and DST-sensitive scheduling - Pattern 4:
DateTimeOffsetfor 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.Nowin databases; store UTC instead. - Treat
DateTimeKind.Unspecifiedas 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:
- Return the resolved timezone block for each location.
- State the recommended implementation in one sentence.
- Include a copy-paste-ready C# snippet.
For code and architecture requests:
- State the recommended approach in one sentence.
- Provide the timezone IDs if relevant.
- Include the minimal working code snippet.
- Mention the package requirement if needed.
- Add one pitfall warning if it matters.
Keep responses concise and code-first.
References
references/timezone-index.md: common Windows and IANA timezone mappingsreferences/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
评论
- …
同一仓库的更多技能
acquire-codebase-knowledge
40k帮你的智能体理解并编写现有代码项目的文档。它有助于新成员快速上手,或者快速了解项目架构。
acreadiness-assess
40k让你的智能体评估一个项目对 AI 的准备程度,并生成报告。它有助于了解项目在使用 AI 工具方面的准备情况。
acreadiness-generate-instructions
40k帮你的智能体根据评估结果编写 AI 工具的指令文件。它有助于改善 AI 与代码的交互方式,并弥补已发现的不足。
acreadiness-policy
40k让你的智能体协助制定或应用 AI 项目评估的政策。它有助于规范项目的评估方式,并确保合规。