zoukankan      html  css  js  c++  java
  • golang -62135596800

    参考下面的代码即可。

    package main
     
    import (
       "time"
       "fmt"
    )
     
    func main() {
       //获取当前时间
       t := time.Now() //2018-07-11 15:07:51.8858085 +0800 CST m=+0.004000001
       fmt.Println(t)
     
       //获取当前时间戳
       fmt.Println(t.Unix()) //1531293019
     
       //获得当前的时间
       fmt.Println(t.Uninx().Format("2006-01-02 15:04:05"))  //2018-7-15 15:23:00
     
       //时间 to 时间戳
       loc, _ := time.LoadLocation("Asia/Shanghai")        //设置时区
       tt, _ := time.ParseInLocation("2006-01-02 15:04:05", "2018-07-11 15:07:51", loc) //2006-01-02 15:04:05是转换的格式如php的"Y-m-d H:i:s"
       fmt.Println(tt.Unix())                             //1531292871
     
       //时间戳 to 时间
       tm := time.Unix(1531293019, 0)
       fmt.Println(tm.Format("2006-01-02 15:04:05")) //2018-07-11 15:10:19
     
       //获取当前年月日,时分秒
       y := t.Year()                 //
       m := t.Month()                //
       d := t.Day()                  //
       h := t.Hour()                 //小时
       i := t.Minute()               //分钟
       s := t.Second()               //
       fmt.Println(y, m, d, h, i, s) //2018 July 11 15 24 59
    }
     
  • 相关阅读:
    python05-循环
    python03-列表
    python03 input
    python02-灭霸的选择
    python学习小记01--萌新的进化
    Linux—-软件安装
    linux-认识与分析日志
    Esxi遇到问题汇总。
    xx
    Pramp mock interview (4th practice): Matrix Spiral Print
  • 原文地址:https://www.cnblogs.com/peteremperor/p/14658902.html
Copyright © 2011-2022 走看看