Date Formats - Real Quick

polaris · · 438 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>For New Go Programmers. </p> <p>Key point about formats: the correct component values (ex. 2006 for year, 15 for hour) must be used. </p> <pre><code>const Format1 = &#34;Jan 2, 2006&#34; const Format2 = &#34;2006-01-02 15:04:05&#34; ... var date1 time.Time input1 := &#34;Apr 1, 2017&#34; date1, _ = time.Parse(Format1, input1) // probably want to check for error output1 := date1.AddDate(1, 1, 1).Format(Format2) // add 1 yr, 1 mo, 1 day &amp; return formatted value log.Println(output1) // prints 2018-05-02 00:00:00 </code></pre> <hr/> <p>I know there are many posts about dates, but this simple concept is often covered over with lots of other info.</p> <hr/>**评论:**<br/><br/>metamatic: <pre><p><a href="http://gotime.agardner.me/" rel="nofollow">It&#39;s Go time</a></p></pre>jayposs: <pre><p>Cool</p></pre>j_d_q: <pre><p><a href="https://golang.org/pkg/time/#pkg-constants" rel="nofollow">Godoc <code>time</code> constants</a> lists the possibilities</p></pre>jayposs: <pre><p>Definitely the Go to for all the details. Think when you first read it, you miss the point of how easy it is to work with date formats.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

438 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传