golang时间
//获取本地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时间的更多相关文章
- Golang时间格式化
PHP中格式化时间很方便,只需要一个函数就搞定: date("Y-m-d H:i:s") 而在Golang中,用的是"2006-01-02 15:04:05"这 ...
- Golang时间函数及测试函数执行时间案例
package main import ( "fmt" "time" ) func main(){ //[时间获取及格式化] //获取当前时间 now_time ...
- 三、golang时间、流程控、函数
一.本篇内容 1.string和strconv使用 2.go中的时间和日期类型 3.流程控制 4.函数讲解 二.string和strconv使用 1. string.HasPrefix(s trin ...
- golang 时间转换的问题
一般在获取到时间字符串,需要将时间字符串格式化为golang的"time.Time"对象的时候,通常有2个函数,分别是. time.Parse(layout, value stri ...
- 随笔:Golang 时间Time
先了解下time类型: type Time struct { // sec gives the number of seconds elapsed since // January 1, year 1 ...
- golang时间转换
1.datetime转换成时间字符串 package main import ( "fmt" "reflect" "time" ) func ...
- golang 时间的比较,time.Time的初始值?
参考: https://golangcode.com/checking-if-date-has-been-set/ https://stackoverflow.com/questions/209243 ...
- golang时间与日期相关函数
- golang中的一些实用功能
0.1.索引 https://waterflow.link/articles/1663921524839 通过使用一些通用代码来节省时间,而无需单独实现它们.以下是一些开发中经常会用到的函数实现的列表 ...
随机推荐
- 八大排序算法之二希尔排序(Shell Sort)
希尔排序是1959 年由D.L.Shell 提出来的,相对直接排序有较大的改进.希尔排序又叫缩小增量排序 基本思想: 先将整个待排序的记录序列分割成为若干子序列分别进行直接插入排序,待整个序列中的记录 ...
- 通过URl将服务器的图片下载到本地并压缩
private void downloadServerPic(final String url1) { new Thread() { @Override public void run() { // ...
- C# 加密解密
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Secur ...
- Java提高篇---Stack
在Java中Stack类表示后进先出(LIFO)的对象堆栈.栈是一种非常常见的数据结构,它采用典型的先进后出的操作方式完成的.每一个栈都包含一个栈顶,每次出栈是将栈顶的数据取出,如下: Stack通过 ...
- EasyUI 格式化DataGrid列
easyui DataGrid中格式化列,如果单价低于20,则使用定义列formatter为红色文本.格式化DataGrid列,我们应该设置formatter属性,这个属性是一个函数.格式化函数包括两 ...
- WINCE6.0组件选择说明
WINCE6.0组件选择说明 图1 RAS/PPP组件前面的√标识表示我们手动选择,TAPI2.0前面的■标识表示选组件时根据依赖关系自动选择的,PPPoE前面的□标识组件没有选择.
- 【leetcode❤python】191. Number of 1 Bits
#-*- coding: UTF-8 -*- class Solution(object): def hammingWeight(self, n): if n<=0:retu ...
- DIV的表单布局
表单布局其实用表格最好了,可是表格的话,无法定位,这个是一个硬伤. <!DOCTYPE html> <html> <head> <meta charset=& ...
- Android 路径大全
1 内部存储路径为/data/data/youPackageName/ 目录结构 //返回cache文件对象 this.getCacheDir(); //返回databases下指定文件 this.g ...
- STREAM Benchmark
STREAM Benchmark及其操作性能分析 文/raywill STREAM 是业界广为流行的综合性内存带宽实际性能 测量 工具之一.随着处理器处理核心数量的增多,内存带宽对于提升整个系统性能越 ...