Go Language time format conversion

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

recently done projects to use the Golang language, encountered the problem of conversion of time format , referring to the online information to write their own code test, to successfully convert, put the code out for later use, but also for the need to view.

<span style= "FONT-SIZE:18PX;" >//time_format.gopackage mainimport ("FMT" "Time") Func main () {FMT. Println ("Hello world!") Returns the current time tnow: = times. Now ()//Time conversion to String,layout must be "2006-01-02 15:04:05" TimeNow: = Tnow.format ("2006-01-02 15:04:05") fmt. Println ("Tnow (Time format):", Tnow) fmt. Println ("Tnow (string format):", TimeNow)//string converted to time, the layout must be "2006-01-02 15:04:05" T, _: = times. Parse ("2006-01-02 15:04:05", "2014-06-15 08:37:18") fmt. Println ("t (time format)", T)//At some point before and after the trueorfalse: = T.after (tnow) If Trueorfalse = = true {fmt. Println ("t (2014-06-15 08:37:18) after Tnow!")} else {fmt. Println ("t (2014-06-15 08:37:18) before Tnow!")} Fmt. Println ()}</span>


Output Result:

Hello world!

Tnow (Time format): 2015-06-15 08:52:32.8861261 +0800 CST

Tnow (string format): 2015-06-15 08:52:32

T (time format) 2014-06-15 08:37:18 +0000 UTC

T (2014-06-15 08:37:18) before Tnow!


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.