Go language time format, a wonderful need to say

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.


In the past, using java,python,php, and other languages, to format a time into a string is the "Yyy-mm-dd hh:mm:ss" method, Golang format method really eye-opener

First look at the Official document description:

Func (Time) Format

Func (t time) Format (layout string) string

Format returns a textual representation of the time value formatted according to layout, which defines the format by Showi ng How the reference time, defined

Mon Jan 2 15:04:05-0700 MST 2006

Would be displayed if it were the value; It serves as an example of the desired output. The same display rules would then is applied to the time value. Predefined layouts Ansic, Unixdate, RFC3339 and others describe standard and convenient representations of the reference T Ime. For more information on the formats and the definition of the reference time, see the documentation for Ansic and the O Ther constants defined by the this package.


Here's a code:

Fmt. Println (time. Now (). Format ("2006-01-02 150405"))


Pay attention to that time, can only be 2006-01-02 15:04:05 minutes, other time is not good enough.




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.