timezone-tools

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Timezone Tools

时区工具

Get current time in any timezone and convert times between different timezones using IANA timezone database.
获取任意时区的当前时间,并使用IANA时区数据库在不同时区之间转换时间。

Quick Start

快速开始

Get current time in a timezone

获取指定时区的当前时间

bash
python scripts/get_time.py" "America/New_York"
bash
python scripts/get_time.py" "America/New_York"

Convert time between timezones

在时区之间转换时间

bash
python scripts/convert_time.py" "America/New_York" "14:30" "Australia/Perth"
bash
python scripts/convert_time.py" "America/New_York" "14:30" "Australia/Perth"

Search for timezone names

搜索时区名称

bash
python scripts/list_timezones.py" "perth"
bash
python scripts/list_timezones.py" "perth"

Instructions

使用说明

When the user asks about time or timezones:
  1. For current time queries (e.g., "What time is it in Tokyo?"):
    • Use
      scripts/get_time.py
      with IANA timezone name
    • If unsure of timezone name, search first with
      list_timezones.py
    • Script outputs: timezone, datetime, day of week, DST status
  2. For time conversions (e.g., "What's 2pm EST in Perth time?"):
    • Use
      scripts/convert_time.py
      with source timezone, time (HH:MM 24-hour), target timezone
    • Script shows source time, target time, and time difference
    • Automatically handles DST changes
  3. For timezone searches:
    • Use
      scripts/list_timezones.py
      with city/country name
    • Returns matching IANA timezone names
当用户询问时间或时区相关问题时:
  1. 当前时间查询(例如:“现在东京几点?”):
    • 使用
      scripts/get_time.py
      并传入IANA时区名称
    • 若不确定时区名称,先使用
      list_timezones.py
      进行搜索
    • 脚本输出:时区、日期时间、星期几、夏令时(DST)状态
  2. 时间转换(例如:“美国东部时间下午2点对应珀斯时间是几点?”):
    • 使用
      scripts/convert_time.py
      并传入源时区、时间(24小时制HH:MM)、目标时区
    • 脚本会显示源时间、目标时间以及时间差
    • 自动处理夏令时变更
  3. 时区搜索
    • 使用
      scripts/list_timezones.py
      并传入城市/国家名称
    • 返回匹配的IANA时区名称

Common Timezones Reference

常用时区参考

For quick reference, see data/common_timezones.json which includes major cities worldwide, with Perth prominently featured.
User's local timezone: The scripts automatically detect your local timezone using
tzlocal
.
如需快速查阅,可查看data/common_timezones.json,其中包含全球主要城市的时区信息,珀斯的时区信息被重点标注。
用户本地时区:脚本会通过
tzlocal
自动检测您的本地时区。

Examples

示例

Example 1: Current time query

示例1:当前时间查询

User: "What time is it in Perth?"
bash
python scripts/list_timezones.py" "perth"
用户:“现在珀斯几点?”
bash
python scripts/list_timezones.py" "perth"

Output: Australia/Perth

输出:Australia/Perth

python scripts/get_time.py" "Australia/Perth"
python scripts/get_time.py" "Australia/Perth"

Output:

输出:

Timezone: Australia/Perth

Timezone: Australia/Perth

Current time: 2025-11-07T15:30:45

Current time: 2025-11-07T15:30:45

Day: Thursday

Day: Thursday

DST: No

DST: No

undefined
undefined

Example 2: Time conversion

示例2:时间转换

User: "I have a meeting at 2pm New York time, what time is that in Perth?"
bash
python scripts/convert_time.py" "America/New_York" "14:00" "Australia/Perth"
用户:“我在纽约的会议是下午2点,对应珀斯时间是几点?”
bash
python scripts/convert_time.py" "America/New_York" "14:00" "Australia/Perth"

Output:

输出:

Source: America/New_York - 2025-11-07T14:00:00 (Thursday, DST: No)

Source: America/New_York - 2025-11-07T14:00:00 (Thursday, DST: No)

Target: Australia/Perth - 2025-11-08T03:00:00 (Friday, DST: No)

Target: Australia/Perth - 2025-11-08T03:00:00 (Friday, DST: No)

Time difference: +13.0h

Time difference: +13.0h

undefined
undefined

Example 3: Multiple timezone search

示例3:多时区搜索

User: "What are the timezone codes for London, Tokyo, and Sydney?"
bash
python scripts/list_timezones.py" "london"
python scripts/list_timezones.py" "tokyo"
python scripts/list_timezones.py" "sydney"
用户:“伦敦、东京和悉尼的时区代码是什么?”
bash
python scripts/list_timezones.py" "london"
python scripts/list_timezones.py" "tokyo"
python scripts/list_timezones.py" "sydney"

Outputs:

输出:

Europe/London

Europe/London

Asia/Tokyo

Asia/Tokyo

Australia/Sydney

Australia/Sydney

undefined
undefined

Time Format

时间格式

  • All times use 24-hour format (HH:MM):
    14:30
    not
    2:30 PM
  • ISO 8601 datetime format for output:
    2025-11-07T14:30:45
  • IANA timezone names (e.g.,
    America/New_York
    , not
    EST
    )
  • 所有时间采用24小时制(HH:MM):使用
    14:30
    而非
    2:30 PM
  • 输出采用ISO 8601日期时间格式:
    2025-11-07T14:30:45
  • 使用IANA时区名称(例如:
    America/New_York
    ,而非
    EST

Troubleshooting

故障排除

"Invalid timezone" error

"无效时区"错误

  • Use IANA timezone names:
    America/New_York
    not
    EST
    or
    Eastern
  • Search with
    list_timezones.py
    if unsure
  • Check data/common_timezones.json for reference
  • 使用IANA时区名称:例如
    America/New_York
    而非
    EST
    Eastern
  • 若不确定,使用
    list_timezones.py
    进行搜索
  • 可参考data/common_timezones.json

"Invalid time format" error

"无效时间格式"错误

  • Use 24-hour format:
    14:30
    not
    2:30 PM
  • Format must be
    HH:MM
    with colon separator
  • 使用24小时制:例如
    14:30
    而非
    2:30 PM
  • 格式必须为带冒号分隔符的
    HH:MM

Missing dependencies

缺少依赖项

Install required Python packages:
bash
pip install tzlocal
安装所需的Python包:
bash
pip install tzlocal

Dependencies

依赖项

  • Python 3.9+
  • tzlocal>=5.0
    - for local timezone detection
  • zoneinfo
    - built-in Python 3.9+ (IANA timezone database)
  • Python 3.9+
  • tzlocal>=5.0
    - 用于检测本地时区
  • zoneinfo
    - Python 3.9+内置模块(IANA时区数据库)

Notes

注意事项

  • Scripts automatically handle Daylight Saving Time (DST)
  • Local timezone is auto-detected from system
  • All timezone data uses IANA Time Zone Database
  • Perth, Australia timezone:
    Australia/Perth
    (UTC+8, no DST)
  • 脚本会自动处理夏令时(DST)
  • 本地时区会从系统自动检测
  • 所有时区数据均使用IANA时区数据库
  • 澳大利亚珀斯的时区:
    Australia/Perth
    (UTC+8,无夏令时)