Go时间格式化和类型互换操作
来源:互联网 发布:大数据产品设计 编辑:程序博客网 时间:2024/05/16 06:47
获取本地时间
// get current timestamp currentTime := time.Now().Local() //print time fmt.Println(currentTime)
指定格式的日期字符类型
// get current timestamp currentTime := time.Now().Local()//format Time, string type newFormat := currentTime.Format("2006-01-02 15:04:05.000") fmt.Println(newFormat)
构造指定时间类型
//build Time 2016-02-17 23:59:59.999, DateTime type myTime := time.Date(0162, time.February, 17, 23, 59, 59, 999, time.UTC) //output the myTime fmt.Println("MyTime:", myTime.Format("2006-01-02 15:04:05.000"))
完整代码:
package mainimport ( "fmt" "time")func FormatTime() { // get current timestamp currentTime := time.Now().Local() //print time fmt.Println(currentTime) //format Time, string type newFormat := currentTime.Format("2006-01-02 15:04:05.000") fmt.Println(newFormat) //build Time 2016-02-17 23:59:59.999, DateTime type myTime := time.Date(0162, time.February, 17, 23, 59, 59, 999, time.UTC) //output the myTime fmt.Println("MyTime:", myTime.Format("2006-01-02 15:04:05.000")) //current milliseconds fmt.Println("milliseconds:", time.Now().UnixNano()/int64(time.Millisecond)) //TODO Changing time layout(form)}func main(){FormatTime()}
欢迎加入我的微信公众号
0 0
- Go时间格式化和类型互换操作
- Go语言时间格式化
- 时间和double类型数据的格式化
- Go 语言中格式化时间
- 时间和时间戳互换
- Jquery 时间类型格式化
- mysql时间类型格式化
- int和string类型互换
- 时间日期格式化操作
- scala 时间格式化操作
- 时间格式化等操作
- 日期/时间格式化操作
- python时间格式化操作
- String类型和Int类型互换
- 时间戳 和 时间格式的互换
- JSP页面时间类型格式化
- 将json时间类型格式化
- Unix时间戳与C# DateTime时间类型互换
- iOS 分类(category)、扩展(Extension)
- 25. Reverse Nodes in k-Group
- PostMessage 跟 SendMessage的区别
- SharePoint2013 IT Professional - Permission
- 摄影学习记录
- Go时间格式化和类型互换操作
- Fragment详解(二):Fragment 与支持库
- PowerDesigner建模经验
- ubuntu的mysql卸载与安装
- String.split()结尾空字符串将被丢弃
- 关于IOS我要学的d
- 高斯模糊效果的简单实现
- tomcat发布web项目的三种方式
- 百度地图API相关教程