Golang Date Time Format & reverse datetime

Source: Internet
Author: User
Tags string back
This is a created article in which the information may have evolved or changed.

Date format time zone

    time := time.Now()    loc, err := time.LoadLocation("")    // 默认UTC        loc, err := time.LoadLocation("Local")    // 一般为CST    loc, err := time.LoadLocation("America/Los_Angeles")    // 美国洛杉矶PDT    loc, _:= time.LoadLocation("Asia/Chongqing")     // CST

Get current time and format

// 格式化// golang中格式不是‘yyyy-MM-dd HH:mm:ss’,而是采用golang诞生时间作为格式t = "2006-01-02 15:04:05" time := time.Now()fmt.Println(time.Format(t))

Formatted date string back to time

// 格式化t = "2006-01-02 15:04:05" // 日期字符串str = "2017-09-13 00:00:01"loc, err := time.LoadLocation("Local")time, err := time.ParseInLocation(t, str, loc)fmt.Println(time)if err == Nil{}
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.