Golang--Time and date summary

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

Golang Time Processing
Related package "Time"

  • Time stamp
    Current time stamp

    Fmt. Println (time. Now (). Unix ()) # 1389058332

  • STR format time
    Current format time

    Fmt. Println (time. Now (). Format ("2006-01-02 15:04:05")) # This is a wonderful, must be this time point, said to be the day of the birth of Go, memory method: 6-1-2-3-4-5# 2014-01-07 09:42:20

  • Timestamp to STR format time

    Str_time: = time. Unix (1389058332, 0). Format ("2006-01-02 15:04:05") fmt. Println (str_time) # 2014-01-07 09:32:12
  • STR format time-to-timestamp
    This is more trouble.

    The_time: = time. Date (1, 7, 5, 4, 0, time). Local) Unix_time: = The_time. Unix () fmt. Println (unix_time) # 389045004

    There is also a way to use time . Parse

    The_time, err: = time. Parse ("2006-01-02 15:04:05", "2014-01-08 09:04:41") if Err = = Nil {unix_time: = the_time. Unix () fmt. Println (unix_time)}# 1389171881
  • Ing



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.