golang

golang 时间Y-m-d h:i:s写法

2020-09-08  本文已影响0人  rushui
package main

import (
    "fmt"
    "strings"
    "time"
)

func main() {
    //str := "2006-01-02 15:04:05"
    str := "Y-m-d h:i:s"
    //str := "ymdhis"
    fmt.Println(NowTime(str))
}

func NowTime(str string) string {
    str = strings.Replace(str, "Y", "2006", -1)
    str = strings.Replace(str, "y", "06", -1)
    str = strings.Replace(str, "m", "01", -1)
    str = strings.Replace(str, "d", "02", -1)
    str = strings.Replace(str, "h", "15", -1)
    str = strings.Replace(str, "i", "04", -1)
    str = strings.Replace(str, "s", "05", -1)
    return time.Now().Format(str)
}
上一篇下一篇

猜你喜欢

热点阅读