Go timestamp and date string conversion to each other

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

Package <textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;">main Import ("FMT" "Time") Func main () {//get timestamp timestamp: = times. Now (). Unix () fmt. PRINTLN (timestamp)//formatted as a string, TM is Time type TM: = time. Unix (timestamp, 0) fmt. Println (TM. Format ("2006-01-02 03:04:05 PM")) fmt. Println (TM. Format ("02/01/2006 15:04:05 PM"))//convert from string to timestamp, the first argument is format, the second is the time string to be converted tm2, _: = times. Parse ("01/02/2006", "02/08/2015") fmt. Println (TM2. Unix ())}</textarea>
12345678910111213141516171819202122232425262728293031323334353637383940414243 Package Main Import ("FMT""Time") funcMain() {//Get timestamptimestamp := Time. Now().Unix()FMT.Println(timestamp) //format as String, TM as time typeTM := Time.Unix(timestamp, 0)FMT.Println(TM.Format("2006-01-02 03:04:05 PM"))FMT.Println(TM.Format("02/01/2006 15:04:05 PM")) //from string to timestamp, first argument is format, second is the time string to convertTM2, _ := Time.Parse("01/02/2006", "02/08/2015") FMT.Println(TM2.Unix())}

go timestamp and date string conversion to each other

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.