golang时间格式化
来源:互联网 发布:鹰朗el01正品淘宝店 编辑:程序博客网 时间:2024/04/20 01:10
golang时间处理
相关包 "time"
当前时间戳
fmt.Println(time.Now().Unix())# 1389058332当前格式化时间
fmt.Println(time.Now().Format("2006-01-02 15:04:05")) # 这是个奇葩,必须是这个时间点, 据说是go诞生之日, 记忆方法:6-1-2-3-4-5# 2014-01-07 09:42:20
时间戳转str格式化时间
str_time := time.Unix(1389058332, 0).Format("2006-01-02 15:04:05")fmt.Println(str_time)# 2014-01-07 09:32:12str格式化时间转时间戳
the_time := time.Date(2014, 1, 7, 5, 50, 4, 0, time.Local)unix_time := the_time.Unix()fmt.Println(unix_time)# 389045004还有一种方法,使用time.Parse
the_time, err := time.Parse("2006-01-02 15:04:05", "2014-01-08 09:04:41")if err == nil { unix_time := the_time.Unix()fmt.Println(unix_time)}# 1389171881
示例
package mainimport ("fmt""time")const (date = "2006-01-02"shortdate = "06-01-02"times = "15:04:02"shorttime = "15:04"datetime = "2006-01-02 15:04:02"newdatetime = "2006/01/02 15~04~02"newtime = "15~04~02")func main() {thisdate := "2014-03-17 14:55:06"timeformatdate, _ := time.Parse(datetime, thisdate)fmt.Println(timeformatdate)convdate := timeformatdate.Format(date)convshortdate := timeformatdate.Format(shortdate)convtime := timeformatdate.Format(times)convshorttime := timeformatdate.Format(shorttime)convnewdatetime := timeformatdate.Format(newdatetime)convnewtime := timeformatdate.Format(newtime)fmt.Println(convdate)fmt.Println(convshortdate)fmt.Println(convtime)fmt.Println(convshorttime)fmt.Println(convnewdatetime)fmt.Println(convnewtime)}
lasttime, _ := time.Now().Format("2006-01-02 15:04:05")
阅读全文
1 0
- golang时间格式化
- golang时间格式化
- golang的json的时间格式化解决方案
- golang时间戳格式化与解析
- Golang学习笔记 - 【杂项】格式化时间成datetime
- golang 格式化输入输出
- Golang之字符串格式化
- Golang 中的格式化输入输出
- golang中的格式化输入输出
- golang json格式化输出
- golang中的格式化输入输出
- go时间格式化必须精确地限定到 golang 指定的时间原点:2006-01-02 15:04:05
- 格式化时间
- 格式化时间
- 时间格式化
- 格式化时间
- 时间格式化
- 格式化时间
- Scapy脚本执行出现警告WARNING解决办法
- oracle GoldenGate 的参数配置
- Charge Flow in sbl1
- 天池数据挖掘比赛技术与套路总结
- wireshark过滤使用
- golang时间格式化
- 什么U盘启动盘制作工具是纯净版的,没有捆绑软件和广告的?
- 记一次自动导出CVS配置始末
- 网络抓包命令 Tcpdump的详细用法
- css学习笔记-动画
- 浅谈Jquery中的bind(),live(),delegate(),on()绑定事件方式
- 程序猿们_一二三四线城市你更愿意选择去哪里工作?
- spring boot 基础日志配置
- 通用itemview