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 ...
随机推荐
- 使用IDEA打开工程未显示左侧工程目录栏
1. 重启IDEA2. 删除要打开的项目文件夹下的.idea文件夹3. open打开项目即可 注意: 是重启IDEA,不是只关闭IDEA的单个窗口 参考: https://blog.csdn.net/ ...
- P1308(字符串类,处理字符串查找)
题目描述 一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次数. 现在,请你编程实现这一功能,具体要求是:给定一个单词,请你输出它在给 ...
- 利用Python进行数据分析 第5章 pandas入门(1)
pandas库,含有使数据清洗和分析工作变得更快更简单的数据结构和操作工具.pandas是基于NumPy数组构建. pandas常结合数值计算工具NumPy和SciPy.分析库statsmodels和 ...
- python第一天---我要入个门
""" 一个用户登录的案例 """ # 永远等待,直到用户输入值 # 变量 name_r = input("请输入用户名" ...
- Python re模块前的正则表达式常用语法小总结
一.正则表达式: (1).正则表达式是干什么的 正则表达式(regular expression)描述了一种字符串匹配的模式(pattern),可以用来检查一个串是否含有某种子串.将匹配的子串替换或 ...
- 使用Python模块儿csv快速处理csv文件
代码如下: import csv with open('test.csv',newline='') as f: reader = csv.reader(f) for row in re ...
- (未完成)ARM-linux 移植 SDL
ref : https://blog.csdn.net/u012075739/article/details/24877639 2. 交叉编译SDL 编译SDL前先要编译其依赖库 tsl ...
- javascript之new操作符
new 运算符做了哪些事情 1.新生成了一个对象 2.链接到原型 3.绑定 this 4.返回新对象 自己实现一个 new function create() { // 创建一个空的对象 let ob ...
- php反转输出字符串(两种方法)
//第一种方法 function fz($a){ echo strrev($a); } fz('adfjdlks'); echo '<br />'; //第二种方法 function ...
- JS权威指南读书笔记(一)
第一章 JavaScript概述 1 JS是一门高端的.动态的.弱类型的编程语言,非常适合面向对象和函数式的编程风格. 第二章 词法结构 1 JS程序是用Unicode字符集编写的. 2 JS是区 ...