Golang獲取時間戳和時間操作

2021-10-18 20:22:55 字數 902 閱讀 3893

time.now().unix()				//時間戳(秒) 

time.now().unixnano() //時間戳(納秒)

time.now().unixnano() / 1e6 //時間戳(毫秒)

time.now().unixnano() / 1e9 //時間戳(納秒轉換為秒)

注:1秒 = 1000毫秒 1毫秒 = 1000微秒 1微秒 = 1000納秒  

1e6是指數表達形式:  1* 10的6次方

nowtime:=time.now().format("2006-01-02 15:04:05")  //要顯示的時間格式,2006-01-02 15:04:05,這幾個值是固定寫法,golang的誕生時間.

fmt.println(nowtime)    //列印結果:2021-02-02 13:22:04

時間戳轉時間字串      

timeunix:=time.now().unix() //時間戳

formattimestr:=time.unix(timeunix,0).format("2006-01-02 15:04:05")

fmt.println(formattimestr) //列印結果:2021-02-02 13:22:04

時間字串轉時間  

formattimestr := "2021-02-02 13:22:04" 

formattime, err := time.parse("2006-01-02 15:04:05", formattimestr)

fmt.println(formattime) //列印結果:2021-02-02 13:22:04 +0000 utc

js獲取時間戳 時間戳轉時間

1 var timestamp date.parse new date 精準到秒2 var timestamp new date valueof 精準到毫秒3.var timestamp new date gettime 精準到毫秒1 var a new date tolocaledatestrin...

Android 獲取時間戳 和時間戳轉日期

獲取系統時間戳 public string gettime 獲取系統時間 long currenttime system.currenttimemillis dateformat formatter new dateformat yyyy年 mm月dd日 hh時mm分ss秒 date date ne...

獲取時間戳

方法 一 system.currenttimemillis 方法 二 calendar.getinstance gettimeinmillis 方法 三 newdate gettime 結果發現 system.currenttimemillis 這種方式速度最快 calendar.getinstan...