首页 > 其他 > 详细

4.3 字符串格式转换成时间格式

时间:2018-03-22 00:53:11      阅读:226      评论:0      收藏:0      [点我收藏+]

package main

import (
    "fmt"
    "time"
)

func main() {

    // If timezone is not defined
    // than Parse function returns
    // the time in UTC timezone.
    t, err := time.Parse("2/1/2006", "31/7/2015")
    if err != nil {
        panic(err)
    }
    fmt.Println(t)

    // If timezone is given than it is parsed
    // in given timezone
    t, err = time.Parse("2/1/2006  3:04 PM MST", "31/7/2015  1:25 AM DST")
    if err != nil {
        panic(err)
    }
    fmt.Println(t)

    // Note that the ParseInLocation
    // parses the time in given location, if the
    // string does not contain time zone definition
    t, err = time.ParseInLocation("2/1/2006  3:04 PM ", "31/7/2015  1:25 AM ", time.Local)
    if err != nil {
        panic(err)
    }
    fmt.Println(t)

}

/*
2015-07-31 00:00:00 +0000 UTC
2015-07-31 01:25:00 +0000 DST
2015-07-31 01:25:00 +0800 CST

*/

4.3 字符串格式转换成时间格式

原文:https://www.cnblogs.com/zrdpy/p/8620831.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!