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的更多相关文章

  1. Beginning Scala study note(3) Object Orientation in Scala

    1. The three principles of OOP are encapsulation(封装性), inheritance(继承性) and polymorphism(多态性). examp ...

  2. Python thread local

    由于GIL的原因,笔者在日常开发中几乎没有用到python的多线程.如果需要并发,一般使用多进程,对于IO Bound这种情况,使用协程也是不错的注意.但是在python很多的网络库中,都支持多线程, ...

  3. Selenium Page object Pattern usage

    使用Selenium的framework,大家免不了要使用他的page object pattern来开发适合自己的framework,原因很简单,page object 可以将测试的对象抽象成一个个 ...

  4. 如果返回结构体类型变量(named return value optimisation,NRVO)

    貌似这是一个非常愚蠢的问题,因为对于具有良好素质的程序员而言,在C中函数返回类型为结构体类型是不是有点不合格,干嘛不用指针做传入传出呢? 测试环境:Linux IOS 3.2.0-45-generic ...

  5. python调用WebService遇到的问题'Document' object has no attribute 'set'

    代码: from suds import WebFault from suds.client import Client url = 'http://******/bns/PtDataSvc.asmx ...

  6. flask之请求与响应、闪现(阅后即焚)、请求扩展(before,after)、中间件、LOCAL对象、偏函数、

    目录 1.flask请求与响应 2.闪现 3.请求扩展 4.中间件 5.LOCAL对象 6.偏函数 templates 1.flask请求与响应 from flask import Flask,req ...

  7. Flask补充--threading.local对象

    目录 Local 局部变量 全局变量 使用threading.local() 自定义threading.local 函数版 面向对象版 通过setattr和getattr实现 每个对象有自己的存储空间 ...

  8. 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 ...

  9. flask 中的 werkzeug Local,LocalStack 和 LocalProxy 技术应用

    什么是 Local wsgi 每次请求,会把过程进行抽离无状态话,过程数据存储在本次请求的全局变量中,使用到了Local. Local 作为每次请求的全局命令空间,属于每次请求的私有 LocalSta ...

随机推荐

  1. 记联想SR850 Raid配置的一个bug

    管理raid阵列时,如果要删除某个指定的阵列,则需要选中阵列名而不能选中虚拟磁盘.如果选中的是虚拟磁盘,点击删除后,会删除整个阵列列表里的第一个阵列,而非虚拟磁盘所在的阵列. 过程如下 联想SR850 ...

  2. 软件素材--c/c++干掉代码的通用方法

    while(1) { sleep(200); } #endif

  3. Python08之分支和循环3(for、while循环)

    一.for语句: for 目标 in 表达式: 循环体 i = "湖人总冠军" for each in i: print(each) 湖 人 总 冠 军 for each in i ...

  4. python学习-59 hashlib模块

    hashlib模块 用于加密相关的操作,3.x里代替了md5模块和sha模块 加密功能 import hashlib obj = hashlib.md5() # 如果在md5里加上自己设置的参数,别的 ...

  5. Burp Suite的安装与使用

    ​ Burp Suite是一个集成化的渗透测试工具,它集合了多种渗透测试组件,使我们自动化地或手工地能更好的完成对web应用的渗透测试和攻击.在渗透测试中,我们使用Burp Suite将使得测试工作变 ...

  6. 2、C语言实现通讯录

    main函数入口: //test.c #include<stdio.h> #include<stdlib.h> #include<string.h> #includ ...

  7. Spring Boot配置文件yml讲解--行内对象的配置方式

    yml行内对象的配置方法,一般是采取 上面的缩进方式,我只想配置在一行怎么处?——

  8. linux安装imagemagick,centos安装imagemagick方法

    1.安装文件格式支持库 yum install tcl-devel libpng-devel libjpeg-devel ghostscript-devel bzip2-devel freetype- ...

  9. sqlserver 转化函数

    --查询系统当前时间select GETDATE() as date;------------------------- 0-14 ------------------select CONVERT(V ...

  10. Redis 如何与数据库事务保持一致

    考虑一个问题,redis 如何 与 数据库保持一致性的问题. 举栗子:如果我们在开发过程中遇到这样的一种情况,我们删除 redis中token 的同时 也需要修改数据库中 储存的 token 的状态为 ...