#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

#127 in Date and time

Download history 188/week @ 2024-06-21 104/week @ 2024-06-28 60/week @ 2024-07-05 45/week @ 2024-07-12 30/week @ 2024-07-19 32/week @ 2024-07-26 84/week @ 2024-08-02 44/week @ 2024-08-09 63/week @ 2024-08-16 51/week @ 2024-08-23 129/week @ 2024-08-30 31/week @ 2024-09-06 49/week @ 2024-09-13 66/week @ 2024-09-20 67/week @ 2024-09-27 33/week @ 2024-10-04

216 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.2–1.7MB
~38K SLoC