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 ...
随机推荐
- logstash 6.6.0 读取nginx日志 插入到elasticsearch中
logstash.conf input { # For detail config for log4j as input, # See: https://www.elastic.co/guide/en ...
- SPSS数据分析基础考题
选择题 1. SPSS发行版本的说法,正确的是: B A. 两年发行一个新版本 B.一年发行一个新版本 C.没有任何规律 D.三年发行三个新版本 2.哪些是SPSS统计分析软件的基本窗口: A A.结 ...
- Jira强制退出时(如意外停电)再启动报Locked错误的几个解决办法
查看jira_home的路径在/opt/atlassian/jira/atlassian-jira/WEB-INF/classes/jira-application.properties文件中查看 方 ...
- Deepin 15.11 install nvidia dirver[mei you an zhuang shu ru fa]
1.firstly, exec: sudo vim /etc/modprobe.d/blacklist-nouveau.conf[create], and input [blacklist nouve ...
- jenkins【目录】:目录
jenkins[目录]:目录 GitLab 自动触发 Jenkins 构建 返回
- [Oracle] - 关于星期(IW和WW)的算法
1. 查看数据库字符集(如果字符集不同,可能显示乱码) select DECODE(parameter, 'NLS_TERRITORY', 'TERRITORY', 'NLS_LANGUAGE', ' ...
- (三)Spring Boot 官网文档学习之默认配置
文章目录 继承 `spring-boot-starter-parent` 覆盖默认配置 启动器 原文地址:https://docs.spring.io/spring-boot/docs/2.1.3.R ...
- Python35之包的创建
包(package) 一.创建一个文件夹,用于存放相关的模块,文件夹的名字即包的名字 二.在文件夹中创建一个__init__.py的模块文件,内容可以为空 三将相关的模块放入文件夹中 这样就相当于创建 ...
- Linux基础-08-进程控制
1. 系统监视和进程控制工具—top和free 1) top命令的功能:top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器. 2) ...
- IDE集成开发环境(pycharm)、基本数据类型、用户的交互、运算符
一.IDE集成开发系统pycharm 目的:让Python编程更方便.高效. pycharm的简单定义: PyCharm是一种Python IDE,带有一整套可以帮助用户在使用Python语言开发时提 ...