rstime 0.1.0

A simple Rust time library with timestamp retrieval and datetime conversion
Documentation
  • Coverage
  • 44.44%
    8 out of 18 items documented0 out of 8 items with examples
  • Size
  • Source code size: 9.12 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 338.05 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Cnkrru/rstime
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Cnkrru

rstime

English | 中文


English

A simple Rust time library with timestamp retrieval and UTC+8 datetime conversion.

Installation

Add to your Cargo.toml:

[dependencies]
rstime = "0.1.0"

Usage

use rstime::timestamp;
use rstime::time;

fn main() {
    // Get timestamp (seconds, microseconds, nanoseconds)
    let t = timestamp::new().get_timestamp();
    println!("s: {}, ms: {}, ns: {}", t.timestamp_s, t.timestamp_ms, t.timestamp_ns);

    // Get UTC+8 datetime (default timezone)
    let dt = time::new().get_time();
    println!("{}-{}-{} {}:{}:{}", dt.year, dt.mouth, dt.day, dt.hour, dt.minute, dt.secend);

    // Change timezone (e.g. UTC+0)
    let dt_utc = time::new().set_timezone(0).get_time();
    println!("UTC: {}-{}-{} {}:{}:{}", dt_utc.year, dt_utc.mouth, dt_utc.day, dt_utc.hour, dt_utc.minute, dt_utc.secend);
}

API

  • timestamp::new() -> timestamp — Creates a default timestamp instance.
  • timestamp::get_timestamp(self) -> Self — Fills the instance with current UNIX timestamp in seconds, microseconds, and nanoseconds.
  • time::new() -> time — Creates a default time instance.
  • time::set_timezone(self, hours: i32) -> Self — Sets the timezone offset in hours.
  • time::get_time(self) -> Self — Converts current timestamp to year/month/day/hour/minute/second with the configured timezone.
  • time::is_leap_year(&self) -> bool — Checks if the stored year is a leap year.

License

MIT


中文

一个简单的 Rust 时间处理库,提供时间戳获取和 UTC+8 日期时间转换功能。

安装

Cargo.toml 中添加:

[dependencies]
rstime = "0.1.0"

使用

use rstime::timestamp;
use rstime::time;

fn main() {
    // 获取时间戳(秒、微秒、纳秒)
    let t = timestamp::new().get_timestamp();
    println!("秒: {}, 微秒: {}, 纳秒: {}", t.timestamp_s, t.timestamp_ms, t.timestamp_ns);

    // 获取 UTC+8 日期时间(默认时区)
    let dt = time::new().get_time();
    println!("{}-{}-{} {}:{}:{}", dt.year, dt.mouth, dt.day, dt.hour, dt.minute, dt.secend);

    // 修改时区(例如 UTC+0)
    let dt_utc = time::new().set_timezone(0).get_time();
    println!("UTC: {}-{}-{} {}:{}:{}", dt_utc.year, dt_utc.mouth, dt_utc.day, dt_utc.hour, dt_utc.minute, dt_utc.secend);
}

API

  • timestamp::new() -> timestamp — 创建默认时间戳实例。
  • timestamp::get_timestamp(self) -> Self — 用当前 UNIX 时间戳(秒、微秒、纳秒)填充实例。
  • time::new() -> time — 创建默认时间实例。
  • time::set_timezone(self, hours: i32) -> Self — 设置时区偏移量,单位为小时。
  • time::get_time(self) -> Self — 将当前时间戳按配置的时区转换为年/月/日/时/分/秒。
  • time::is_leap_year(&self) -> bool — 判断当前存储的年份是否为闰年。

许可协议

MIT