golang string 常用api
package main
import (
"fmt"
"time"
)
func main() {
nowTime := time.Now();
fmt.Printf("%v\n",nowTime)
fmt.Printf("%02d.%02d.%4d\n", nowTime.Year(), nowTime.Month(), nowTime.Year())
nowTimeStr :=nowTime.Format("2006-01-02 15:04:05")
fmt.Printf("%v\n",nowTimeStr)
addTime :=nowTime.Unix()+3600*24;
tm := time.Unix(addTime, 0)
fmt.Printf("addTime: %v\n",time.Unix(addTime, 0).Format("2006-01-02 15:04:05"))
isTrue := tm.After(nowTime)
fmt.Printf("%v\n",isTrue)
subTime :=tm.Sub(nowTime)
fmt.Printf("时间差毫秒 %v ,秒 %v\n",subTime.Milliseconds(),subTime.Seconds())
m, _ := time.ParseDuration("-10m")
nowTimeMin :=nowTime.Add(m)
fmt.Printf("nowTimeMin %v\n ",nowTimeMin)
tenAfter, _ :=time.ParseDuration("10m");
nowTimetenAfter :=nowTime.Add(tenAfter)
fmt.Printf("nowTimetenAfter %v\n ",nowTimetenAfter)
}
输出
GOROOT=D:\softinstall\GO_HOME #gosetup
GOPATH=C:\Users\HCP\go #gosetup
D:\softinstall\GO_HOME\bin\go.exe build -o C:\Users\HCP\AppData\Local\Temp\___go_build_strTest_go.exe D:/softinstall/GO/src/mygo/lcw/test/strTest.go #gosetup
C:\Users\HCP\AppData\Local\Temp\___go_build_strTest_go.exe #gosetup
false
false
true
2
nodehasw,asdasd,qweqwe
count 4
wodehasw,asdasd,qweqwe
wodehasw
asdasd
qweqwe
newStr2 wodehaswlcw asdasdlcw qweqwe
newpool &{wodehasw,asdasd,qweqwe 0 -1} and 23
str: 23
val23 <nil>