zoukankan      html  css  js  c++  java
  • Go-内置time包

    一.导入包

    import "time"

    二.转换成Time对象

    • 获取当前时间:time. Now ()
    • 自定义时间:time. Date(year int, month Month, day, hour, min, sec, nsec int, loc *Location)

    三.Time对象的方法

    年月日周

    • Date() : 返回时间的日期信息 返回值int类型
    • Year() : 返回年 返回值int类型
    • Month () : 返回月 返回值Month类型
    • Day () : 返回日 返回值int类型
    • YearDay() : 一年中对应的天 返回值int类型

    年,星期范围编号

    • ISOWeek () : 返回年,星期范围编号int类型

    时分秒

    • Clock () : 返回 时分秒 返回值int类型

    • Hour () : 返回时返回值int类型

    • Minute () : 返回分 返回值int类型

    • Second () : 返回秒 返回值int类型

    • Nanosecond () : 返回纳秒 返回值int类型

    时间戳

    • Unix() :时间戳 返回值 int64
    • UnixNano() :时间戳(纳秒) 返回值 int64

    时区

    • Location ():时区返回值 *Location
    • Zone() :时区偏差 返回值string+int

    四.时间序列化和返序列化以及比较与计算

    参考https://www.jianshu.com/p/9d5636d34f17

    列化和返序列化

    func (t Time) MarshalBinary() ([]byte, error) {} // 时间序列化

    func (t Time) UnmarshalBinary(data []byte) error {} // 反序列化

    func (t Time) MarshalJSON() ([]byte, error) {} // 时间序列化

    func (t Time) MarshalText() ([]byte, error) {} // 时间序列化

    func (t Time) GobEncode() ([]byte, error) {} // 时间序列化

    func (t Time) GobDecode() ([]byte, error) {} // 时间序列化

    比较与计算

    func (t Time) IsZero() bool {} // 是否是零时时间

    func (t Time) After(u Time) bool {} // 时间在u 之前

    func (t Time) Before(u Time) bool {} // 时间在u 之后

    func (t Time) Equal(u Time) bool {} // 时间与u 相同

    func (t Time) Add(d Duration) Time {} // 返回t +d 的时间点

    func (t Time) Sub(u Time) Duration {} // 返回 t-u

    func (t Time) AddDate(years int, months int, days int) Time {} 返回增加了给出的年份、月份和天

  • 相关阅读:
    vue.js环境配置步骤及npm run dev报错解决方案
    消息处理之performSelector
    iOS开发网络篇—发送GET和POST请求(使用NSURLSession)
    iOS手机号正则表达式并实现344格式 (正则的另一种实现方式)
    IOS开发——正则表达式验证手机号、密码
    iOS网络请求之---GET和POST
    CLLocation
    ios本地文件内容读取,.json .plist 文件读写
    UITableViewCell的4种样式
    iOS开发通过代码方式使用AutoLayout (NSLayoutConstraint + Masonry)
  • 原文地址:https://www.cnblogs.com/pythonywy/p/11895749.html
Copyright © 2011-2022 走看看