1. 将YYYYmmddHHDD类型的时间转化成unix时间戳

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    
    package main
    
    import (
        "fmt"
        "time"
    )
    
    func main() {
        stringTime := "201601010000"
        tmpTime, _ := time.ParseInLocation("200601021504", stringTime, time.Local)
        unixTime := tmpTime.Unix()
        fmt.Printf("The Unix time of %v is %v\n", stringTime, unixTime)
    }
  2. 将unix时间戳转化成YYYYmmddHHDD格式的时间

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    
    package main
    
    import (
        "fmt"
        "strconv"
        "time"
    )
    
    func main() {
        i, err := strconv.ParseInt("1405544146", 10, 64)
        if err != nil {
            panic(err)
        }
        tm := time.Unix(i, 0)
        fmt.Println(tm.Format("200601021504"))
    }