Return local beginning of day time object in Go
Both the title and the text of the question asked for "a local [Chicago] beginning of today time." The Bod function in the question did that correctly. The accepted Truncate function claims to be a better solution, but it returns a different result; it doesn't return a local [Chicago] beginning of today time. For example,
package main
import (
"fmt"
"time"
)
func Bod(t time.Time) time.Time {
year, month, day := t.Date()
return time.Date(year, month, day, 0, 0, 0, 0, t.Location())
}
func Truncate(t time.Time) time.Time {
return t.Truncate(24 * time.Hour)
}
func main() {
chicago, err := time.LoadLocation("America/Chicago")
if err != nil {
fmt.Println(err)
return
}
now := time.Now().In(chicago)
fmt.Println(Bod(now))
fmt.Println(Truncate(now))
}
Output:
2014-08-11 00:00:00 -0400 EDT
2014-08-11 20:00:00 -0400 EDT
The time.Truncate method truncates UTC time.
The accepted Truncate function also assumes that there are 24 hours in a day. Chicago has 23, 24, or 25 hours in a day.
Return local beginning of day time object in Go的更多相关文章
- Beginning Scala study note(3) Object Orientation in Scala
1. The three principles of OOP are encapsulation(封装性), inheritance(继承性) and polymorphism(多态性). examp ...
- Python thread local
由于GIL的原因,笔者在日常开发中几乎没有用到python的多线程.如果需要并发,一般使用多进程,对于IO Bound这种情况,使用协程也是不错的注意.但是在python很多的网络库中,都支持多线程, ...
- Selenium Page object Pattern usage
使用Selenium的framework,大家免不了要使用他的page object pattern来开发适合自己的framework,原因很简单,page object 可以将测试的对象抽象成一个个 ...
- 如果返回结构体类型变量(named return value optimisation,NRVO)
貌似这是一个非常愚蠢的问题,因为对于具有良好素质的程序员而言,在C中函数返回类型为结构体类型是不是有点不合格,干嘛不用指针做传入传出呢? 测试环境:Linux IOS 3.2.0-45-generic ...
- python调用WebService遇到的问题'Document' object has no attribute 'set'
代码: from suds import WebFault from suds.client import Client url = 'http://******/bns/PtDataSvc.asmx ...
- flask之请求与响应、闪现(阅后即焚)、请求扩展(before,after)、中间件、LOCAL对象、偏函数、
目录 1.flask请求与响应 2.闪现 3.请求扩展 4.中间件 5.LOCAL对象 6.偏函数 templates 1.flask请求与响应 from flask import Flask,req ...
- Flask补充--threading.local对象
目录 Local 局部变量 全局变量 使用threading.local() 自定义threading.local 函数版 面向对象版 通过setattr和getattr实现 每个对象有自己的存储空间 ...
- Java Thread Local – How to use and code sample(转)
转载自:https://veerasundar.com/blog/2010/11/java-thread-local-how-to-use-and-code-sample/ Thread Local ...
- flask 中的 werkzeug Local,LocalStack 和 LocalProxy 技术应用
什么是 Local wsgi 每次请求,会把过程进行抽离无状态话,过程数据存储在本次请求的全局变量中,使用到了Local. Local 作为每次请求的全局命令空间,属于每次请求的私有 LocalSta ...
随机推荐
- spaces的坑
spacemacs的坑,改镜像源,不能使用退格 emacs25以上可以装spacemacs 目前在mac上装emacs26.1 使用spacemacs的时候会有melpa.org访问慢或者访问不了的问 ...
- keepalived+lvs tcp check 引起的后端服务报Connection reset by peer
方法一: 取消LVS方式进行tcp转发,进而改为http方式反向代理,问题即可解决. 当然,这是在业务允许使用http的情况下,如果必须使用tcp协议,那就得使用下面的方法了. 方法二: 修改keep ...
- Django的小记
大致按流程列出来 在pycham中创建Django project时要确定机器上的版本及你要用的版本,机器上一般情况下默认最新版本2.1(2018年11月),根据需要下载相应版本 创建好工程后就要创建 ...
- php str_getcsv解决explode不能解决的问题
php str_getcsv解决explode不能解决的问题 <pre><?php$str = "中国,广东省,广州市,天河区,'113.329884,23.154799' ...
- Ubuntu下U盘文件只读的解决办法
转自linux公社:http://www.linuxidc.com/Linux/2012-12/76130.htm Ubuntu下U盘出现文件系统只读的问题了.症状为无法删除U盘中现有文件,无法向U盘 ...
- 迅雷下载敏感资源 迅雷应版权方要求无法下载 μTorrent使用方法(六种方法,值得你看)(22)
1. 解决方案1 1.1 声明 此方法只适用于迅雷极速版,迅雷X不管用. 修改后下载有些磁力链接或种子,依然无反应.不是说该方法无效,而是有些种子资源不佳,很难下载,需要等半天才能连接上开始下载.如果 ...
- a+b的问题
题目描述: 给定两个整数 a, b (a, b 均不超过 int 类型的表示范围),求出 a + b 的和. 输入描述: 每行输入两个整数 a 和 b,用空格隔开. 输出描述: a + b 的值. 样 ...
- CodeForces-166B-Polygons
B. Polygons time limit per test:2 seconds memory limit per test:256 megabytes input:standard input o ...
- Python15之字符串的格式语句与操作符
一.字符串的format()函数 字符串1.format(赋值) 字符串中必须表明需要格式化的位置 format()函数使用时,花括号中的值表明字符串中 ...
- 二十二、DMA驱动
一.DMA简介 DMA(Direct Memory Access,直接内存存取),DMA传输将数据从一个地址空间复制到另外一个地址空间.传输过程由DMA控制器独立完成,它并没有拖延CPU的工作,可以让 ...