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 ...
随机推荐
- css position属性
absolute, 屏幕为参照, 但固定在页面上,随页面滚动而动. fixed, 父元素没有指定position属性(或position属性为static时)==>屏幕为参照,固定在屏幕的某个位 ...
- PhpExcel笔记,phpExcel中文帮助手册
下面是总结的几个使用方法 include 'PHPExcel.php'; include 'PHPExcel/Writer/Excel2007.php'; //或者include 'PHPExcel/ ...
- [转]Java 征途:行者的地图
前段时间应因缘梳理了下自己的 Java 知识体系, 成文一篇望能帮到即将走进或正在 Java 世界跋涉的程序员们. 第一张,基础图 大约在 2003 年我开始知道 Java 的(当时还在用 Delph ...
- 基础知识《八》---Java反射机制
1.反射可以做什么 2.反射相关的API 3.获取Class运行时类的实例的三种方法: 1)通过运行时类本身的.class属性***** Class clazz= Person.class; 2)通过 ...
- ios iphone6 Plus 的适配问题
最近更新一个老程序,发现在iphone6 plus上用nslog打印出的screen 的frame还是320*568, 不是414*736, 查了一下,原来需要设置iphone6 plus的启动画面才 ...
- UTF8编码转换(C#)
例如: UTF8---ISO-8859-1 string string = "这是中文";Encoding utf8 = Encoding.UTF8; Encoding ISO = ...
- simpleTree简单使用
SimpleTree使用起来比较方便,它实现了最基本的树形菜单的功能,包括1个JS文件.1个CSS文件和5个图标文件. 使用时只要将相关文件复制到项目中,并在相应的页面引用它就行,例如: <!D ...
- 【编程之美】CPU
今天开始看编程之美 .第一个问题是CPU的使用率控制,微软的问题果然高大上,我一看就傻了,啥也不知道.没追求直接看答案试了一下.发现自己电脑太好了,4核8线程,程序乱飘.加了一个进程绑定,可以控制一个 ...
- 【elasticsearch】python下的使用
有用链接: 最有用的:http://es.xiaoleilu.com/054_Query_DSL/70_Important_clauses.html 不错的博客:http://www.cnblogs. ...
- 查看进程,按内存从大到小 ,查看进程,按CPU利用率从大到小排序
查看进程,按内存从大到小 ps -e -o "%C : %p : %z : %a"|sort -k5 -nr 查看进程,按CPU利用率从大到小排序 ps -e -o "% ...