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 ...
随机推荐
- Mathtype安装与最简破解
1.MathType资源 链接: https://pan.baidu.com/s/1UapJCcfU7Me_rIWdAe5nfw 提取码: 1y9i 2.破解 我之前的30天试用期过了,没来得 ...
- python基础篇(一)
PYTHON基础篇(一) 变量 赋值 输入,输出和导入 A:输入 B:输出 C:导入 运算符 A:算数运算符 B:比较运算符 C:赋值运算符 D:位运算符 E:逻辑运算符 F:成员运算符 G:身份运算 ...
- 通用mybatis单表操作接口
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "- ...
- LeetCode 145. 二叉树的后序遍历(Binary Tree Postorder Traversal)
145. 二叉树的后序遍历 145. Binary Tree Postorder Traversal 题目描述 给定一个二叉树,返回它的 后序 遍历. LeetCode145. Binary Tree ...
- [WCF] - 使用 bat 批处理文件将 WCF 服务部署为 Windows Service
1. 添加 Windows Service 项目 2. 添加 WCF 项目引用 3. 更新 App.config 配置文件(可以从 WCF的 Web.config 拷贝过来),设置服务地址. 4. 配 ...
- 大数据架构(PB级)
1.随着互联网快速发展,数据量的快速膨胀,我们日增3000多亿数据量,因此需要针对PB级存储.几百TB的增量数据处理架构设计 2.系统逻辑划分总图: 暂不便透露 3.系统架构图: 4.大数据计算引擎我 ...
- Word 域代码使用方法
插入域「Crtl+F9」 更新域「F9」 切换域代码「Alt+F9」 批量删除域 打开 Word 文档,全选,按下「Alt+F9」键,将 Word 中所有的域结果切换为域代码的形式. 调出" ...
- 用selenium控制已打开的浏览器
在使用selenium进行自动化测试会遇到,手工打开浏览器,做了一部分操作后,并打开相关页面后再执行相关的自动化脚本. 如何使用selenium来接管先前已打开的浏览器呢?醍提出一个Google Ch ...
- IDE集成开发环境(pycharm)、基本数据类型、用户的交互、运算符
一.IDE集成开发系统pycharm 目的:让Python编程更方便.高效. pycharm的简单定义: PyCharm是一种Python IDE,带有一整套可以帮助用户在使用Python语言开发时提 ...
- 利用Python进行数据分析 第7章 数据清洗和准备(1)
学习时间:2019/10/25 周五晚上22点半开始. 学习目标:Page188-Page217,共30页,目标6天学完,每天5页,预期1029学完. 实际反馈:集中学习1.5小时,学习6页:集中学习 ...