AI Agent Hub
Back to skills
Python Timestamp Converter icon

Python Timestamp Converter

Development Updated 2026.08.30

Paste the following prompt into your AI chat to install this skill:

Install @user_15292d5a/yjkj-cn-timestamp-tool according to https://skillhub.cn/install/skillhub.md.

About this skill

Problem

Engineers often need to move between Unix timestamps and readable dates: a log value like 1720000000 must be interpreted, while an API date such as 2024-07-01 12:00:00 may need to become a timestamp. Hand-written datetime code can easily introduce timezone, second/millisecond, or formatting mistakes.

How It Works

cn-timestamp-tool wraps common conversions with the Python standard library, without external dependencies or an API key. Its core capabilities are:
- Timestamp to date-time: render Unix timestamps as readable times for logs and API responses
- Date-time to timestamp: convert human-readable dates to int timestamps for queries or storage fields
- Current timestamp: return the current Unix timestamp in seconds or milliseconds
- Timezone support: use zoneinfo for different zones, defaulting to Asia/Shanghai
A typical flow parses the input, selects the timezone, uses datetime and time to format or normalize the value, then outputs the requested type. argparse provides a command-line entry point for scripts and quick debugging.

Boundaries

It covers common local timestamp conversion, not full timezone arithmetic, NTP synchronization, or business calendar logic. Check whether date strings carry timezone information, and do not mix second- and millisecond-based fields. If the project needs cross-timezone reporting or DST-sensitive auditing, validate results against explicit business rules.

Use Cases

  • Convert Unix timestamp 1720000000 to Asia/Shanghai time.
  • Convert 2024-07-01 12:00:00 to a seconds timestamp.
  • Get current seconds or milliseconds timestamp for test data.
  • Convert date time to timestamp for Asia/Shanghai or zones.

Best For

  • Backend engineer: reads Unix timestamps in logs as local time.
  • API engineer: converts dates to second timestamps for queries.
  • Test engineer: generates current second/millisecond timestamps for data.
  • Script author: normalizes date strings into timestamps in local scripts.