rstime
A lightweight, zero-dependency enhanced time library for Rust, built entirely using the standard library. Fills the gaps left by std::time with full date, time, formatting, parsing, and clock capabilities.
Features
- Zero Dependencies: Built entirely using Rust's standard library
- Date Type:
Date(year/month/day) with weekday calculation and leap year detection - Time Type:
Time(hour/minute/second/millisecond) with 12/24-hour support - DateTime Type: Combined
DateTimewith Unix timestamp conversion - Duration Types:
Duration(positive) andTimeDelta(signed) for calculations - Formatting: Custom format strings like
{YYYY}-{MM}-{DD} {HH}:{mm}:{ss} - Parsing: Parse date/time from strings with format-based and ISO 8601 support
- Clock: System clock for real time, monotonic clock for performance measurement
- Arithmetic: Full arithmetic support with operator overloading
Quick Start
Add rstime to your Cargo.toml:
[]
= { = "../rstime" }
Current Time
use ;
Formatting
use ;
Date Arithmetic
use ;
Unix Timestamps
use DateTime;
Parsing
use parse_iso8601;
Format Tokens
| Token | Meaning | Example |
|---|---|---|
{YYYY} |
4-digit year | 2026 |
{YY} |
2-digit year | 26 |
{MM} |
2-digit month | 05 |
{DD} |
2-digit day | 10 |
{HH} |
2-digit 24-hour | 14 |
{hh} |
2-digit 12-hour | 02 |
{mm} |
2-digit minute | 05 |
{ss} |
2-digit second | 09 |
{SSS} |
3-digit millisecond | 037 |
{W} |
Abbreviated weekday | Sun |
{WW} |
Full weekday | Sunday |
{AMPM} |
AM/PM uppercase | PM |
{ampm} |
am/pm lowercase | pm |
Clock
use ;
Documentation
Generate documentation:
License
MIT License
Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
中文文档
中文文档请查看 rs-docs