Go

Go formatting time

Published Time : 2025-10-21

Preface

In the development of using Go, sometimes formatting time is required, and the formatting time of the Go language is a bit special. Please use it on January 2, 2006 at 15:04:05

Go formatting time

format time

//img.enjoy4fun.com/news_icon/d3rlgetdm8bc72oq55ag.png

The output result is

//img.enjoy4fun.com/news_icon/d3rlgor8hlms72q66ukg.png

//img.enjoy4fun.com/news_icon/d3rlgsr8hlms72q67480.png

The output result is

//img.enjoy4fun.com/news_icon/d3rlh338hlms72q67e50.png

//img.enjoy4fun.com/news_icon/d3rlh8r8hlms72q67o0g.png

The output result is

//img.enjoy4fun.com/news_icon/d3rlhfr8hlms72q683l0.png

Can use Chinese

//img.enjoy4fun.com/news_icon/d3rlhlj8hlms72q68d50.png

The output result is

//img.enjoy4fun.com/news_icon/d3rlhp38hlms72q68hmg.png

12 hour clock and AM/PM

//img.enjoy4fun.com/news_icon/d3rli3b8hlms72q69010.png

The output result is

//img.enjoy4fun.com/news_icon/d3rli8tdm8bc72oq7spg.png

Milliseconds, microseconds, nanoseconds

//img.enjoy4fun.com/news_icon/d3rliegfe6kc72qfgl1g.png

The output result is

//img.enjoy4fun.com/news_icon/d3rlikgfe6kc72qfgscg.png

summary

The parameter of the time. Format() method is not a "pattern string", but a specific date and time example. You must use fixed numbers such as 2006, 01, 02, 15, 04, and 05 to represent the corresponding year, month, day, hour, minute, and second.