實際業務中需要大量處理時間日期時區資料,封裝好一些方法方便後面呼叫:
package mainimport (
"errors""
fmt"
"time")
const
( binano = "
2006-01-02 15:04:05.000000000
"bimicro = "
2006-01-02 15:04:05.000000
"bimil = "
2006-01-02 15:04:05.000
"bisec = "
2006-01-02 15:04:05
"bicst = "
2006-01-02 15:04:05 +0800 cst
"biutc = "
2006-01-02 15:04:05 +0000 utc
"bidate = "
2006-01-02
"bitime = "
15:04:05")
func main()
//時間字串轉時間
func timestr2time(str string
) (time.time, error)
//時間字串轉時間戳
func timestr2timestamp(str string
) (int64, error)
//時間戳轉時間 秒
func timestamp2timesec(stamp int64) time.time
//base...
func timestr2timebasic(value string, resultformat string, resultloc *time.location) (time.time, error)
vart time.time
for _, usef :=range useformat
break
}
if t ==gettimedefault(resultloc)
if resultformat == ""
st :=t.format(resultformat)
fixedt, _ :=time.parseinlocation(resultformat, st, resultloc)
return
fixedt, nil
}func timestr2timestampbasic(str
string, format string, loc *time.location) (int64, error)
return (int64(t.unixnano()) * 1) /1e9, nil
}func timestamp2time(stamp int64, nsec int64) time.time
//獲取time預設值, 造乙個錯誤
func gettimedefault(loc *time.location) time.time
func getlocationdefault(loc *time.location) *time.location
return
loc}
Oracle中時間相互轉換
1.轉字串型別 select sysdate from dual 獲取oracle系統時間 select to char sysdate,yyyy mm dd hh mm ss from dual oracle系統時間轉字串 2.轉date型別 字串轉date select to date 2019...
時間戳 日期相互轉換
當天0點日期 date y m d h i s mktime 0,0,0,date m date d date y 當天0點時間戳 mktime 0,0,0,date m date d date y 當前日期 time date y m d h i s 當前時間戳 unixtime strtotim...
python中時間的相互轉換
import time import datetime 時間戳 timer time.time 格式化的字串時間 struct time time.strftime y m d x struct time2 time.strftime y m d h m s 時間物件 結構化時間 t time.lo...