<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 = "Jan 2, 2006"
const Format2 = "2006-01-02 15:04:05"
...
var date1 time.Time
input1 := "Apr 1, 2017"
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 & 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'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
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传