golang time and duration
package mainimport "fmt"import "time"func main() { p := fmt.Println // We'll start by getting the current time. now := time.Now() p("time.Now(): ", now) // You can build a "time" struct by providing the // year, month, day, etc. Times are always associated // with a "Location", i.e. time zone. then := time.Date(2009, 11, 17, 20, 34, 58, 651387237, time.UTC) p("time.Date(): ", then) p("==================================") // You can extract the various components of the time // value as expected. p("time.Date().Year(): ", then.Year()) p("time.Date().Month(): ", then.Month()) p("time.Date().Day(): ", then.Day()) p("time.Date().Hour(): ", then.Hour()) p("time.Date().Minute(): ", then.Minute()) p("time.Date().Second(): ", then.Second()) p("time.Date().Nanosecond(): ", then.Nanosecond()) p("time.Date().Location(): ", then.Location()) // The Monday-Sunday "Weekday" is also available. p("time.Date().Weekday(): ", then.Weekday()) p("==================================") // These methods compare two times, testing if the // first occurs before, after, or at the same time // as the second, respectively. p("time.Date().Before(now): ", then.Before(now)) p("time.Date().After(now): ", then.After(now)) p("time.Date().Equal(now): ", then.Equal(now)) p("==================================") // The "Sub" methods returns a "Duration" representing // the interval between two times. diff := now.Sub(then) p("time.Now().Sub(time.Date()): ", diff) p("==================================") // We can compute the length of the duration in // various units. p("time.Date().Sub(then).Hours(): ", diff.Hours()) p("time.Date().Sub(then).Minutes(): ", diff.Minutes()) p("time.Date().Sub(then).Seconds(): ", diff.Seconds()) p("time.Date().Sub(then).Nanoseconds(): ", diff.Nanoseconds()) p("==================================") // You can use "Add" to advance a time by a given // duration, or with a "-" to move backwards by a // duration. p("time.Date().Sub(now).Add(now.Sub(then)): ", now.Add(diff)) p("time.Date().Sub(then).Add(-(now.Sub(then))): ", then.Add(-diff))}
golang time and duration的更多相关文章
- golang time.Duration()的问题解疑
原文: How to multiply duration by integer? 看到golang项目中的一段代码, ---------------------------------------- ...
- Golang, 以17个简短代码片段,切底弄懂 channel 基础
(原创出处为本博客:http://www.cnblogs.com/linguanh/) 前序: 因为打算自己搞个基于Golang的IM服务器,所以复习了下之前一直没怎么使用的协程.管道等高并发编程知识 ...
- channel Golang
Golang, 以17个简短代码片段,切底弄懂 channel 基础 (原创出处为本博客:http://www.cnblogs.com/linguanh/) 前序: 因为打算自己搞个基于Golang的 ...
- golang 裸写一个pool池控制协程的大小
这几天深入的研究了一下golang 的协程,读了一个好文 http://mp.weixin.qq.com/s?__biz=MjM5OTcxMzE0MQ==&mid=2653369770& ...
- TODO:Golang UDP连接简单测试慎用Deadline
TODO:Golang UDP连接简单测试慎用Deadline UDP 是User Datagram Protocol的简称, 中文名是用户数据报协议,是OSI(Open System Interco ...
- Ubuntu14.04+RabbitMQ3.6.3+Golang的最佳实践
目录 [TOC] 1.RabbitMQ介绍 1.1.什么是RabbitMQ? RabbitMQ 是由 LShift 提供的一个 Advanced Message Queuing Protocol ...
- golang开发缓存组件
代码地址github:cache 花了一天时间看了下实验楼的cache组件,使用golang编写的,收获还是蛮多的,缓存组件的设计其实挺简单的,主要思路或者设计点如下: 全局struct对象:用来做缓 ...
- golang中的race检测
golang中的race检测 由于golang中的go是非常方便的,加上函数又非常容易隐藏go. 所以很多时候,当我们写出一个程序的时候,我们并不知道这个程序在并发情况下会不会出现什么问题. 所以在本 ...
- [Golang] 一个简易代理池
晚上写了一个代理池,就是在一个代理网站上爬取代理ip和端口以及测试是否可用.接下来可能考虑扩展成一个比较大的 golang实现的代理池. 简易版代码: package main import ( &q ...
随机推荐
- python项目在windows下运行出现编码错误的解法
在启动文件里面加入 import sysreload(sys) sys.setdefaultencoding('GB2312') 这样在windows下调试运行神马的,就不会报错了. 当然发布时,建议 ...
- 一次Android脱壳training
一.查壳 jeb载入发现没有代码,怀疑加壳 用查壳工具查壳 (爱加密) apktool解包 得到其 package name: loading.androidmanual main activity ...
- 【GoLang】GoLang 遍历 map、slice、array方法
代码示例: map1 := make(map[string]string) map1["a"] = "AAA" map1["b"] = &q ...
- Maven学习总结
转载至:http://www.cnblogs.com/xdp-gacl/p/3498271.html 一 入门 一.Maven的基本概念 Maven(翻译为"专家","内 ...
- 通过代理连接go01ge
日本:https://pac.mcplay.cn/jp.pac台湾:https://pac.mcplay.cn/tw.pac如果想上Google可以试试简单的方法,在ie的代理自动配置脚本设置这个p ...
- ffmpeg-20160526-git-bin
ESC 退出 0 进度条开关 1 屏幕原始大小 2 屏幕1/2大小 3 屏幕1/3大小 4 屏幕1/4大小 S 下一帧 [ -2秒 ] +2秒 ; -1秒 ' +1秒 下一个帧 -> -5秒 f ...
- Django~urls.py--->views.py
The 'r' in front of each regular expression string is optional but recommended. It tells Python that ...
- 20151130test->20160530
过了6个月了,有些长进么?哈 go go go 开源镜像 http://mirrors.163.com/
- 完美解决:Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=6&arch=x
如题: 原因:没有配置resolv.conf 解决方法: 到/etc目录下配置resolv.conf加入nameserver IP,如: nameserver 8.8.8.8nameserver 8. ...
- iOS开发MAC下配置svn
版本控制对于团队合作显得尤为重要,那么如何在iOS开发中进行版本控制呢?在今天的博客中将会介绍如何在MAC下配置SVN服务器,如何导入我们的工程,如何在Xcode中进行工程的checkOut和Comm ...