本文介绍了去:time.Format:如何理解'2006-01-02'布局的含义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个时间变量,我想打印年,月和日。
从文档中,似乎可以使用任何布局。例如,我看不到布局之间的差异2006-01-02,2006-10-10,1999-02-02。



但是,只有布局2006- 01-02返回我所期望的。
我在哪里可以找到关于布局中'2006','01','02'含义的文档?



我在这里玩过不同的布局:

解决方案

Mon Jan 2 15:04:05 -0700 MST 2006 是参考时间,这意味着布局需要使用该确切日期。这里有,但基本上通过对日期时间的每个部分使用唯一值,它能够确定每个部分的位置(年,月等)实际上是自动的。



更正了操场

a>


Given a time variable, I want to print year, month, and day.From the documentation, it seems that any layout can be used. For example, I don't see difference between layouts 2006-01-02, 2006-10-10, 1999-02-02.

However, only layout 2006-01-02 returns what I expect. Where can I find documentation on the meanings of '2006', '01', '02' in the layout?

I played here with different layouts: go playground: testing layouts

解决方案

Mon Jan 2 15:04:05 -0700 MST 2006 is the reference time, which means the layout needs to use that exact date. There's more information here, but basically by using unique values for each part of a datetime it's able to tell where each part (year, month, etc) actually is automatically.

Corrected go playground

这篇关于去:time.Format:如何理解'2006-01-02'布局的含义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 01:47