Golang之时间、日期类型
2024-10-18 22:27:31
孤身只影的一直小地鼠,艰难的走在路上
package main import (
"fmt"
"time"
) //获取时间的格式
func testTime() {
now := time.Now()
fmt.Printf("current time:%v\n", now) year := now.Year()
month := now.Month()
day := now.Day()
hour := now.Hour()
minute := now.Minute()
second := now.Second()
// %02d表示不够2位的话,就补0
fmt.Printf("%02d-%02d-%02d %02d:%02d:%02d\n ", year, month, day, hour, minute, second)
} //获取时间戳
func testTimestamp(timestamp int64) {
timeObj := time.Unix(timestamp, )
year := timeObj.Year()
month := timeObj.Month()
day := timeObj.Day()
hour := timeObj.Hour()
minute := timeObj.Minute()
second := timeObj.Second() fmt.Printf("current timestamp:%d\n", timestamp)
fmt.Printf("%02d-%02d-%02d %02d:%02d:%02d\n", year, month, day, hour, minute, second)
} func processTask() {
fmt.Printf("do task\n")
} //定时器
func testTicker() {
ticker := time.Tick( * time.Second)
for i := range ticker {
fmt.Printf("%v\n", i)
processTask()
}
} //time.Duration用来表示纳秒
func testConst() {
//一些常量
fmt.Printf("nano second:%d\n", time.Nanosecond)
fmt.Printf("micro second:%d\n", time.Microsecond)
fmt.Printf("mili second:%d\n", time.Millisecond)
fmt.Printf("second:%d\n", time.Second)
}
//时间格式化
func testFormat() {
now := time.Now()
timeStr := now.Format("2006-01-02 15:04:05")
fmt.Printf("time:%s\n", timeStr)
} func main() {
//testTime()
//timestamp := time.Now().Unix()
//testTimestamp(timestamp)
//testTicker()
//testConst()
testFormat()
}
最新文章
- 用JMeter测试monggodb的请求
- grep命令详解
- Allegro padstack
- cordova环境配置
- Use Visual studio 2010 build Python2.7.10
- caffe net 可视化工具
- unzip 命令使用
- PowerShell remoting中的second-hop问题
- XAF应用开发教程(二)业务对象模型之简单类型属性
- KDE声音服务器 arts
- HDU 1233 还是畅通工程(最小生成树,prim)
- 无责任共享 Coursera、Udacity 等课程视频
- linux共享windows资料
- mysql中AES_ENCRYPT、AES_DNCRYPT及CONVERT的用法
- DL4NLP——词表示模型(三)word2vec(CBOW/Skip-gram)的加速:Hierarchical Softmax与Negative Sampling
- 基于telegraf+influxdb+grafana进行postgresql数据库监控
- Xdebug的优点!php代码开发
- 初识Spring Boot框架(二)之DIY一个Spring Boot的自动配置
- eXosip2 编译安装
- Oracle完全复制表结构的存储过程