在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ GO/ Go時(shí)間日期實(shí)例
Go panic錯(cuò)誤處理實(shí)例
Go命令行參數(shù)實(shí)例
Go可變參數(shù)的函數(shù)實(shí)例
Go通道同步實(shí)例
Go非阻塞通道操作實(shí)例
Go指針實(shí)例
Go數(shù)字解析實(shí)例
Go語(yǔ)言指針
Go超時(shí)(timeouts)實(shí)例
Go速率限制實(shí)例
Go信號(hào)實(shí)例
Go Base64編碼實(shí)例
Go計(jì)時(shí)器實(shí)例
Go命令行標(biāo)志實(shí)例
Go原子計(jì)數(shù)器實(shí)例
Go語(yǔ)言切片
Go隨機(jī)數(shù)實(shí)例
Go語(yǔ)言類(lèi)型轉(zhuǎn)換
Go排序?qū)嵗?/span>
Go時(shí)間格式化/解析實(shí)例
Go URL解析實(shí)例
Go字符串函數(shù)實(shí)例
Go語(yǔ)言常量
Go for循環(huán)語(yǔ)句實(shí)例
Go函數(shù)多個(gè)返回值實(shí)例
Go切片實(shí)例
Go行過(guò)濾器實(shí)例
Go語(yǔ)言接口
Go語(yǔ)言數(shù)組
Go語(yǔ)言變量
Go字符串格式化實(shí)例
Go斷續(xù)器實(shí)例
Go if/else語(yǔ)句實(shí)例
Go通道緩沖實(shí)例
Go錯(cuò)誤實(shí)例
Go語(yǔ)言映射
Go執(zhí)行過(guò)程實(shí)例
Go函數(shù)實(shí)例
Go有狀態(tài)的goroutines實(shí)例
Go按自定義函數(shù)排序?qū)嵗?/span>
Go語(yǔ)言作用域規(guī)則
Go時(shí)代(Epoch)實(shí)例
Go變量實(shí)例
Go互斥體實(shí)例
Go語(yǔ)言范圍(range)
Go程序?qū)嵗?/span>
Go語(yǔ)言入門(mén)
Go通道路線(xiàn)實(shí)例
Go閉包(匿名函數(shù))實(shí)例
Go Select實(shí)例
Go通道范圍實(shí)例
Go集合函數(shù)實(shí)例
Hello World程序?qū)嵗?/span>
Go環(huán)境變量實(shí)例
Go語(yǔ)言運(yùn)算符
Go讀取文件實(shí)例
Go延遲(defer)實(shí)例
Go SHA1哈希實(shí)例
Go語(yǔ)言條件和決策
Go語(yǔ)言錯(cuò)誤處理
Go通道實(shí)例
Go指針實(shí)例
Go時(shí)間日期實(shí)例
Go語(yǔ)言字符串
Go語(yǔ)言循環(huán)
Go語(yǔ)言基礎(chǔ)語(yǔ)法
Go語(yǔ)言開(kāi)發(fā)環(huán)境安裝配置
Go常量實(shí)例
Go語(yǔ)言結(jié)構(gòu)體
Go寫(xiě)文件實(shí)例
Go正則表達(dá)式實(shí)例
Go JSON實(shí)例
Go語(yǔ)言教程
Go關(guān)閉通道實(shí)例
Go接口實(shí)例
Go語(yǔ)言遞歸
Go switch語(yǔ)句實(shí)例
Go函數(shù)遞歸實(shí)例
Go退出程序?qū)嵗?/span>
Go語(yǔ)言程序結(jié)構(gòu)
Go范圍實(shí)例
Go語(yǔ)言函數(shù)
Go工作池實(shí)例
Go語(yǔ)言數(shù)據(jù)類(lèi)型

Go時(shí)間日期實(shí)例

Go編程為時(shí)間和持續(xù)時(shí)間提供廣泛的支持; 這里有些例子。我們將從獲取當(dāng)前時(shí)間開(kāi)始。也可以通過(guò)提供年,月,日等來(lái)構(gòu)建時(shí)間結(jié)構(gòu)。時(shí)間總是與位置(即時(shí)區(qū))相關(guān)聯(lián)。

具體的每個(gè)函數(shù),可參考示例中的代碼 -

所有的示例代碼,都放在 F:\worksp\golang 目錄下。安裝Go編程環(huán)境請(qǐng)參考:http://www.yiibai.com/go/go_environment.html

json.go的完整代碼如下所示 -

package main

import "fmt"
import "time"

func main() {
    p := fmt.Println

    // We'll start by getting the current time.
    now := time.Now()
    p(now)

    // You can build a `time` struct by providing the
    // year, month, day, etc. Times are always associated
    // with a `Location`, i.e. time zone.
    then := time.Date(
        2009, 11, 17, 20, 34, 58, 651387237, time.UTC)
    p(then)

    // You can extract the various components of the time
    // value as expected.
    p(then.Year())
    p(then.Month())
    p(then.Day())
    p(then.Hour())
    p(then.Minute())
    p(then.Second())
    p(then.Nanosecond())
    p(then.Location())

    // The Monday-Sunday `Weekday` is also available.
    p(then.Weekday())

    // These methods compare two times, testing if the
    // first occurs before, after, or at the same time
    // as the second, respectively.
    p(then.Before(now))
    p(then.After(now))
    p(then.Equal(now))

    // The `Sub` methods returns a `Duration` representing
    // the interval between two times.
    diff := now.Sub(then)
    p(diff)

    // We can compute the length of the duration in
    // various units.
    p(diff.Hours())
    p(diff.Minutes())
    p(diff.Seconds())
    p(diff.Nanoseconds())

    // You can use `Add` to advance a time by a given
    // duration, or with a `-` to move backwards by a
    // duration.
    p(then.Add(diff))
    p(then.Add(-diff))
}

執(zhí)行上面代碼,將得到以下輸出結(jié)果 -

F:\worksp\golang>go run time.go
2017-01-21 16:59:10.8307711 +0800 CST
2009-11-17 20:34:58.651387237 +0000 UTC
2009
November
17
20
34
58
651387237
UTC
Tuesday
true
false
false
62916h24m12.179383863s
62916.403383162185
3.774984202989731e+06
2.2649905217938387e+08
226499052179383863
2017-01-21 08:59:10.8307711 +0000 UTC
2002-09-14 08:10:46.472003374 +0000 UTC