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 ...
随机推荐
- robot:循环遍历数据库查询结果是否满足要求
使用list类型变量@{}接收查询结果,再for循环遍历每行数据,取出需要比较的数值
- List<E>
List<E>——列表 有序,存储和读取的顺序是一致的 由整数索引 允许重复 add(int index,E element)——将元素插入指定位置 get(int index)——获取指 ...
- 手把手带你入门神秘的RxJava
1.什么是RxJava• Rx是Reactive Extensions的简写,翻译为响应的扩展.也就是通过由一方发出信息,另一方响应信息并作出处理的核心框架代码. • 该框架由微软的架构师Erik M ...
- QT qml TreeView展示数据结构于界面
Class QAbstractItemModel: 使用QML的TreeView类来展示树状的结构,对应的是QT的Model/View模型.这个model是一个数据模型,要为TreeView提供一个 ...
- dotnet core JWT Demo
JWT介绍 JSON Web Token(JWT)是目前最流行的跨域身份验证解决方案.JWT的官网地址:https://jwt.io/. 通俗地来讲,JWT是能代表用户身份的令牌,可以使用JWT令牌在 ...
- Echarts 不能百分比显示或显示有问题
1,设折线图宽为100%(如:容器div的class=“RiBarBot”宽为880px),刚初始化时隐藏折线图(或后期刷新.隐藏与显示折线图时),当点击显示折线图时,获取到的宽只有100px,并不是 ...
- tomcat+java+redis环境linux安装
最近要加一个环境测试,自力更生,丰衣足食,记下来下次安装环境速度快点 java jdk-1.80_131 64位 这个jdk 对于初次下载的人要注意,oracel现在不登录不让下载,而注册用户时页面无 ...
- python 之 并发编程(守护线程与守护进程的区别、线程互斥锁、死锁现象与递归锁、信号量、GIL全局解释器锁)
9.94 守护线程与守护进程的区别 1.对主进程来说,运行完毕指的是主进程代码运行完毕2.对主线程来说,运行完毕指的是主线程所在的进程内所有非守护线程统统运行完毕,主线程才算运行完毕详细解释:1.主 ...
- stm32f103re stop模式下降低功耗
一端口设置1.将N.C的GPIO统一配置为GPIO_Mode_AIN: 2.检查输入引脚,按照不工作时候的状态相应配置为 IPD/IPU,即避免在内部上/下拉电阻上消耗电流,而且该电流理论值为VCC ...
- 音量调节条-封装通用的ProgressBar组件
import React, { Component } from 'react' import PropTypes from 'prop-types' import assign from 'obje ...