孤身只影的一直小地鼠,艰难的走在路上

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()
}

最新文章

  1. 用JMeter测试monggodb的请求
  2. grep命令详解
  3. Allegro padstack
  4. cordova环境配置
  5. Use Visual studio 2010 build Python2.7.10
  6. caffe net 可视化工具
  7. unzip 命令使用
  8. PowerShell remoting中的second-hop问题
  9. XAF应用开发教程(二)业务对象模型之简单类型属性
  10. KDE声音服务器 arts
  11. HDU 1233 还是畅通工程(最小生成树,prim)
  12. 无责任共享 Coursera、Udacity 等课程视频
  13. linux共享windows资料
  14. mysql中AES_ENCRYPT、AES_DNCRYPT及CONVERT的用法
  15. DL4NLP——词表示模型(三)word2vec(CBOW/Skip-gram)的加速:Hierarchical Softmax与Negative Sampling
  16. 基于telegraf+influxdb+grafana进行postgresql数据库监控
  17. Xdebug的优点!php代码开发
  18. 初识Spring Boot框架(二)之DIY一个Spring Boot的自动配置
  19. eXosip2 编译安装
  20. Oracle完全复制表结构的存储过程

热门文章

  1. setTimeout 方法带参数传递
  2. CNN入门笔记
  3. 浏览器。浏览器对象检测、Chrome调试工具
  4. leetcode455
  5. 使用django + celery + redis 异步发送邮件
  6. VBA 编写类
  7. Redis基本操作-list
  8. java.util包简介
  9. 漫画描述HDFS工作原理
  10. DateJsonValueProcessor日期处理