英文:
what this time format in golang time.Now().UTC().Format("0102150405")
问题
我看到代码中的时间格式是"0102150405",但我不知道这是什么格式。有人知道吗? 😊
time.Now().UTC().Format("0102150405")
英文:
I saw the time format "0102150405" in the code, but I don't know what's the format is, Does anyone have an idea about it? 😂
time.Now().UTC().Format("0102150405")
答案1
得分: 4
(2006年1月2日15:04:05,格林尼治标准时间西七小时)。
该值被记录为名为Layout的常量,如下所示。
作为Unix时间,这是1136239445。由于MST是GMT-0700,
Unix date命令将打印出参考时间:
星期一,2006年1月2日15:04:05 MST
您可以使用它来格式化您获得的time
值。
0102150405
表示想要将time.Now()
格式化为类似于"${month}${day}${hour}${minute}${second}"
的string
。
> 下面是布局字符串的组成部分的摘要。每个元素都以参考时间元素的格式化示例显示。只有这些值会被识别。在布局字符串中,未被识别为参考时间的文本在格式化期间会被原样输出,并且预计在解析输入时也会原样出现。
>
> 年份:"2006" "06"
>
> 月份:"Jan" "January" "01" "1"
>
> 星期几:"Mon" "Monday"
>
> 月份中的日期:"2" "_2" "02"
>
> 年份中的天数:"__2" "002"
>
> 小时:"15" "3" "03"(下午或上午)
>
> 分钟:"4" "04"
>
> 秒钟:"5" "05"
>
> 上午/下午标记:"PM"
更多信息:
<details>
<summary>英文:</summary>
(January 2, 15:04:05, 2006, in time zone seven hours west of GMT).
That value is recorded as the constant named Layout, listed below.
As a Unix time, this is 1136239445. Since MST is GMT-0700,
the reference would be printed by the Unix date command as:
Mon Jan 2 15:04:05 MST 2006
You can use it to format the `time` value you got.
`0102150405` means want to format `time.Now()` as `string` like `"${month}${day}${hour}${minute}${second}"`.
> Here is a summary of the components of a layout string. Each element shows by example the formatting of an element of the reference time. Only these values are recognized. Text in the layout string that is not recognized as part of the reference time is echoed verbatim during Format and expected to appear verbatim in the input to Parse.
>
> Year: "2006" "06"
>
> Month: "Jan" "January" "01" "1"
>
> Day of the week: "Mon" "Monday"
>
> Day of the month: "2" "_2" "02"
>
> Day of the year: "__2" "002"
>
> Hour: "15" "3" "03" (PM or AM)
>
> Minute: "4" "04"
>
> Second: "5" "05"
>
> AM/PM mark: "PM"
See more:
- https://pkg.go.dev/time#pkg-constants
- https://pkg.go.dev/time#Time.Format
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论