<18> go time

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。
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())}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.