Go time formatting and type swapping operations

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

Get local time

    // get current timestamp    currentTime := time.Now().Local()    //print time    fmt.Println(currentTime)

Specifies the format of the date character type

// get current timestamp    currentTime := time.Now().Local()//format Time, string type    newFormat := currentTime.Format("2006-01-02 15:04:05.000")    fmt.Println(newFormat)

Constructs a specified time type

2016-02-1723:59:59.999, DateTime type    myTime := time.Date(0162, time.February17235959999, time.UTC)    //output the myTime    fmt.Println("MyTime:", myTime.Format("2006-01-02 15:04:05.000"))

Full code:

Package Mainimport ("FMT"    "Time") func Formattime () {//Get current timestamp currenttime: = time. now(). Local()//print Time FMT. Println(currenttime)//format time, String type Newformat: = CurrentTime. Format("2006-01-02 15:04:05.000") FMT. Println(Newformat)//build time .- Geneva- -  at: -:59.999, DateTime type myTime: = time. Date(0162, Time. February, -, at, -, -,999, Time. UTC)//output the MyTime FMT. Println("MyTime:", MyTime. Format("2006-01-02 15:04:05.000"))//current milliseconds FMT. Println("milliseconds:", Time. now(). Unixnano()/int64 (time. Millisecond))//todo changing time layout (form)}func main () {Formattime ()}

Welcome to my public number.

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.