//获取本地location
toBeCharge := "2015-01-01 00:00:00" //待转化为时间戳的字符串 注意 这里的小时和分钟还要秒必须写 因为是跟着模板走的 修改模板的话也可以不写
timeLayout := "2006-01-02 15:04:05" //转化所需模板
loc, _ := time.LoadLocation("Local") //重要:获取时区
theTime, _ := time.ParseInLocation(timeLayout, toBeCharge, loc) //使用模板在对应时区转化为time.time类型
sr := theTime.Unix() //转化为时间戳 类型是int64
fmt.Println(theTime) //打印输出theTime 2015-01-01 15:15:00 +0800 CST
fmt.Println(sr) //打印输出时间戳 1420041600 //时间戳转日期
dataTimeStr := time.Unix(sr, 0).Format(timeLayout) //设置时间戳 使用模板格式化为日期字符串
fmt.Println(dataTimeStr)

golang时间的更多相关文章

  1. Golang时间格式化

    PHP中格式化时间很方便,只需要一个函数就搞定: date("Y-m-d H:i:s") 而在Golang中,用的是"2006-01-02 15:04:05"这 ...

  2. Golang时间函数及测试函数执行时间案例

    package main import ( "fmt" "time" ) func main(){ //[时间获取及格式化] //获取当前时间 now_time ...

  3. 三、golang时间、流程控、函数

    一.本篇内容 1.string和strconv使用 2.go中的时间和日期类型 3.流程控制 4.函数讲解 二.string和strconv使用 1.  string.HasPrefix(s trin ...

  4. golang 时间转换的问题

    一般在获取到时间字符串,需要将时间字符串格式化为golang的"time.Time"对象的时候,通常有2个函数,分别是. time.Parse(layout, value stri ...

  5. 随笔:Golang 时间Time

    先了解下time类型: type Time struct { // sec gives the number of seconds elapsed since // January 1, year 1 ...

  6. golang时间转换

    1.datetime转换成时间字符串 package main import ( "fmt" "reflect" "time" ) func ...

  7. golang 时间的比较,time.Time的初始值?

    参考: https://golangcode.com/checking-if-date-has-been-set/ https://stackoverflow.com/questions/209243 ...

  8. golang时间与日期相关函数

  9. golang中的一些实用功能

    0.1.索引 https://waterflow.link/articles/1663921524839 通过使用一些通用代码来节省时间,而无需单独实现它们.以下是一些开发中经常会用到的函数实现的列表 ...

随机推荐

  1. 【转】启动 Eclipse 弹出“Failed to load the JNI shared library jvm.dll”错误的解决方法! .

    转载地址:http://blog.csdn.net/zyz511919766/article/details/7442633 原因1:给定目录下jvm.dll不存在. 对策:(1)重新安装jre或者j ...

  2. Argus

    Argus Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 10186 Accepted: 4801 Description A ...

  3. Poj(2253),Dijkstra松弛条件的变形

    题目链接:http://poj.org/problem?id=2253 题意: 给出两只青蛙的坐标A.B,和其他的n-2个坐标,任一两个坐标点间都是双向连通的.显然从A到B存在至少一条的通路,每一条通 ...

  4. HDU 4630 No Pain No Game 线段树 和 hdu3333有共同点

    No Pain No Game Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  5. javascript + jquery函数大全

    JAVASCRIPT Array 函数   array创建数组 concat()连接两个或更多的数组,并返回结果. join()把数组中所有元素组成字符串. pop()删除并返回数组的最后一个元素 s ...

  6. c#调用cmd的ping命令

    private static string CmdPing(string strIp) { Process p = new Process(); p.StartInfo.FileName = &quo ...

  7. 查看博客模板的css代码

    1.可以去模板列表里选择一个模板 http://www.cnblogs.com/Skins.aspx 目前使用的模板是http://www.cnblogs.com/SkinUser.aspx?Skin ...

  8. Know How To Use Check Box Mapping Of Other Values Property In Oracle Forms

    Check Box Mapping of Other Values specifies how any fetched or assigned value that is not one of the ...

  9. hdu 1800 (map)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1800 Flying to the Mars Time Limit: 5000/1000 MS (Java/ ...

  10. 线程入门之优先级priority

    package com.thread; /** * 优先级: * Thread.MAX_PRIORITY:最大优先级 10 * Thread.MIN_PRIORITY:最小优先级 1 * Thread ...