<18> go time


import (
    "fmt"
    "time"
)

func main() {
    p := fmt.Println
    // 2015-11-30 19:18:48.264366857 +0800 CST
    now := time.Now()
    p(now)

    // 返回time.Time 
    // 2009-11-17 20:34:58.651387237 +0000 UTC
    then := time.Date(2009, 11, 17, 20, 34, 58, 651387237, time.UTC)
    p(then)

    // 2009
    p(then.Year())
    // November
    p(then.Month())
    // 17
    p(then.Day())
    // 20
    p(then.Hour())
    // 34
    p(then.Minute())
    // 58
    p(then.Second())
    // 651387237
    p(then.Nanosecond())
    // UTC
    p(then.Location())
    // Tuesday
    p(then.Weekday())

    // true
    p(then.Before(now))
    // false
    p(then.After(now))
    // false
    p(then.Equal(now))

    // 52886h48m22.514729668s
    diff := now.Sub(then)
    p(diff)

    p(diff.Hours())
    p(diff.Minutes())
    p(diff.Seconds())
    p(diff.Nanoseconds())

    // 2015-11-30 11:23:21.166116905 +0000 UTC
    p(then.Add(diff))
    // 2003-11-06 05:46:36.136657569 +0000 UTC
    p(then.Add(-diff))

    now := time.Now()
    secs := now.Unix()
    nanos := now.UnixNano()
    fmt.Println(now)

    p(t.Format("3:04PM"))
    p(t.Format("Mon Jan _2 15:04:05 2006"))
    p(t.Format("2006-01-02T15:04:05.999999-07:00"))
    p(t.Format("2006-01-02 15:04:05"))
    form := "3 04 PM"
    t2, _ := time.Parse(form, "8 41 PM")
    p(t2)

    fmt.Printf("%d-%02d-%02dT%02d:%02d:%02d-00:00\n",
        t.Year(), t.Month(), t.Day(),
        t.Hour(), t.Minute(), t.Second())

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值