教程集 www.jiaochengji.com
教程集 >  Golang编程  >  golang教程  >  正文 golang 时间和时间戳的转换

golang 时间和时间戳的转换

发布时间:2022-03-24   编辑:jiaochengji.com
教程集为您提供golang 时间和时间戳的转换等资源,欢迎您收藏本站,我们将为您提供最新的golang 时间和时间戳的转换资源
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;"><path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"/></svg><h4>时间 - - > 时间戳</h4> <pre><code> t := time.Now() fmt.Println(t) t1 := t.Unix() fmt.Println(t1) </code></pre>

打印结果:

2019-05-27 19:49:41.2935796 0800 CST m= 0.002989701
1558957781

时间戳类型默认为int64

<h4>
时间戳 - - >时间</h4> <pre><code> tm := time.Unix(t1,0) fmt.Println(tm) </code></pre>

打印结果:

2019-05-27 19:49:41 0800 CST

<h4>
字符串转为时间</h4> <pre><code> todayZero, _ := time.ParseInLocation("2006-01-02 15:04:05","2019-07-16 10:50:04.778", time.Local) fmt.Println(todayZero) </code></pre>

打印结果:
2019-07-16 10:50:04.778 0800 CST

到此这篇关于“golang 时间和时间戳的转换”的文章就介绍到这了,更多文章或继续浏览下面的相关文章,希望大家以后多多支持JQ教程网!

您可能感兴趣的文章:
php 创建以unix时间戳命名的文件夹
Javascript时间戳与php时间戳转换时要注意什么
golang 时间和时间戳的转换
python时间戳是什么
Golang 时间的处理
php 获取今日、昨日、上周、本月的起始与结束时间戳
php中什么是时间戳?
php时间函数strtotime的深入理解
php 时间戳函数总结与示例
php时间戳转换

[关闭]
~ ~