#gostd #time #go-standard-library #go-to-rust #api-bindings

gostd_time

Package time provides functionality for measuring and displaying time. time包提供了时间的显示和测量用的函数。日历的计算采用的是公历。

11 stable releases

1.1.1 Jun 27, 2024
1.0.9 Mar 22, 2024
1.0.6 Nov 22, 2021

#148 in Date and time

Download history 25/week @ 2024-07-22 37/week @ 2024-07-29 86/week @ 2024-08-05 44/week @ 2024-08-12 62/week @ 2024-08-19 145/week @ 2024-08-26 41/week @ 2024-09-02 16/week @ 2024-09-09 54/week @ 2024-09-16 87/week @ 2024-09-23 56/week @ 2024-09-30 22/week @ 2024-10-07 29/week @ 2024-10-14 24/week @ 2024-10-21 42/week @ 2024-10-28 56/week @ 2024-11-04

152 downloads per month
Used in 7 crates (2 directly)

MIT license

190KB
3.5K SLoC

gostd_time

Package time provides functionality for measuring and displaying time. The calendrical calculations always assume a Gregorian calendar, with no leap seconds.

time包提供了时间的显示和测量用的函数。日历的计算采用的是公历。

  • time库在rust实现 gostd::time
  • time库支持macOSX 和linux平台,通过libc库调用C函数实现 time::Now()
  • time,支持各种格式显示时间。
  • docs.rs文档增加例子程序"RUN"按钮,但是要复制代码本地运行,在rust play运行不了(因为下载量没到前100)。
  • v1.0.3,开始time支持local时区信息自动从系统读取,可以用time::Now()获取本地时间。
  • v1.1.0,开始支持windo10平台的正常编译运行,由于平台差异,暂时获取不到本地时区信息,默认取UTC时间,可以传入时区格式化本地时间。

Example

fn main() {
    use gostd_time as time;

    let t = time::Date(2009, 11, 10, 14, 30, 12, 13, time::UTC.clone());
    assert_eq!(
        t.String(),
        "2009-11-10 14:30:12.000000013 +0000 UTC".to_string()
    );
    assert_eq!(t.Format(time::RFC822), "10 Nov 09 14:30 UTC".to_string());
    assert_eq!(
        t.Format(time::RFC1123),
        "Tue, 10 Nov 2009 14:30:12 UTC".to_string()
    );
    println!("default: {}", t);
    println!("RFC822: {}", t.Format(time::RFC822));
    println!("RFC1123: {}", t.Format(time::RFC1123));
}


Dependencies

~1.3–1.8MB
~39K SLoC