1 Star 0 Fork 0

c01dface/s-go-example

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
time.go 1.28 KB
一键复制 编辑 原始数据 按行查看 历史
c01dface 提交于 2024-12-17 11:04 . add time.go
package main
// Go offers extensive support for times and durations
import (
"fmt"
"time"
)
func main() {
p := fmt.Println
// We'll start by getting the current time
now := time.Now()
p(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(then)
// You can extract the various components of the time value as expected
p(then.Year())
p(then.Month())
p(then.Day())
p(then.Hour())
p(then.Minute())
p(then.Second())
p(then.Nanosecond())
p(then.Location())
// The Monday-Sunday Weekday is also available
p(then.Weekday())
// These methods compare two times, testing if the first occurs before, after
// or at the same time as the second, respectively.
p(then.Before(now))
p(then.After(now))
p(then.Equal(now))
// The Sub methods returns a Duration representing the interval
// between two times.
diff := now.Sub(then)
p(diff)
// we can compute the length of the duration in various units.
p(diff.Hours())
p(diff.Minutes())
p(diff.Seconds())
p(diff.Nanoseconds())
// You can use Add to advance a time by a given duration, or with
// a - to move backwards by a duration.
p(then.Add(diff))
p(then.Add(-diff))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/vmalloc/s-go-example.git
git@gitee.com:vmalloc/s-go-example.git
vmalloc
s-go-example
s-go-example
master

搜索帮助