time模块

基于C标准库进行封装

time结构体

  1. pub struct Time {
  2. pub:
  3. year int
  4. month int
  5. day int
  6. hour int
  7. minute int
  8. second int
  9. unix int
  10. }

time方法

  1. //返回月份的字符串简称
  2. pub fn (t Time) smonth() string
  3. //计算unix时间
  4. pub fn (t &Time) calc_unix() int
  5. //增加秒
  6. pub fn (t Time) add_seconds(seconds int)
  7. //增加天
  8. pub fn (t Time) add_days(days int) Time
  9. //某个时间距离当前时间有多久
  10. pub fn (t Time) relative() string
  11. ...

公共函数

  1. //返回当前时间
  2. pub fn now() Time
  3. //返回时间
  4. pub fn new_time(t Time) Time
  5. //进程休眠,等待参数指定的时间长度:
  6. //秒: n*time.second
  7. //毫秒: n*time.millisecond
  8. //微秒: n*time.microsecond
  9. //纳秒: n*time.nanosecond
  10. //nanosecond = Duration(1)
  11. //microsecond = Duration(1000 * nanosecond)
  12. //millisecond = Duration(1000 * microsecond)
  13. //second = Duration(1000 * millisecond)
  14. //minute = Duration(60 * second)
  15. //hour = Duration(60 * minute)
  16. pub fn wait(duration Duration)
  17. //判断是否闰年
  18. pub fn is_leap_year(year int) bool
  19. ...