zoukankan      html  css  js  c++  java
  • 4.3 字符串格式转换成时间格式

    
    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
    
    */
    
    
  • 相关阅读:
    简单对拍
    搜索感想
    L1434滑雪
    记忆化搜索
    L3956棋盘
    USACO 数字三角形
    枚举顺序
    蓝桥计算
    用户态和内核态IO过程
    Mybatis的结果集中的Do要不要有setter
  • 原文地址:https://www.cnblogs.com/zrdpy/p/8620831.html
Copyright © 2011-2022 走看看