go语言中,导入time包,很简单。
func main() { timestamp := time.Now().Unix() fmt.Println(tstime(timestamp)) fmt.Println(timets(tstime(timestamp))) } func tstime(a int64) string { tm := time.Unix(a,0) return tm.Format("2006-01-02 15:04:05") } func timets(a string) int64 { t,err := time.Parse("2006-01-02 15:04:05",a) if err != nil { return 0 } return t.Unix() }
python中 一样简单。
import time a = "2017-03-16 13:30:00" print(time.time()) print(time.localtime(1489641715)) print(time.mktime( time.strptime(a,'%Y-%m-%d %H:%M:%S')))