自当地时间上午8点以来,将时间经过的时间与Boost
Getting the time elapsed since 8am local time with boost
,由于大多数DST时髦的东西发生在午夜左右,我认为简单地从"上午8点"中减去当前时间应该是安全的,但这不是解决方案,我非常非常舒适。
(在以下内容中,假定机器的当地时间是美国/new_york,这是我目的的安全假设)
要解释我要寻找的东西,这就是我在python中做的方式
from datetime import datetime,date,time
print ( datetime.now() - datetime.combine( date.today(), time(8,0,0) ) ).total_seconds()
,或者如果我有点̶
from datetime import datetime,date,time
import pytz
tz = pytz.timezone('America/New_York') #local time is always New York
now = pytz.UTC.localize(datetime.utcnow()).astimezone(tz) # now in this timezone
eight_am = tz.localize( datetime.combine( now.date(), time(8,0,0) ) )
(now - eight_am).total_seconds()
我将如何使用Boost实现C 中的每个人?
我会回答自己的第一部分:
namespace pt = boost::posix_time;
pt::ptime now = pt::second_clock::local_time();
pt::ptime then = pt::ptime(now.date(),pt::hours(8));
pt::time_duration dt = now - then;
std::cout << dt.total_seconds() << std::endl;
相关文章:
- 为什么根据测量位置测量经过的时间时会有很大的不同?
- 如何比较两个经过的时间?
- 为什么这个经过的时间(帧时间)计算会锁定我的游戏
- 获取标准::未来<T>::wait_for的经过时间
- C++ 时间机器无法正确计算经过的时间量
- 填充 unordered_map (c++) 后 malloc 的经过时间
- 自当地时间上午8点以来,将时间经过的时间与Boost
- 如何获得Microsoft TTS演讲的经过的时间
- 获取自C++执行以来经过时间的最干净,最简单的方法
- 在 Linux 中,非常高的经过(挂钟)时间和低系统时间的含义
- 16.66ms 帧时间.当 sleep() 只经过整毫秒时,你如何获得完美的 60 fps
- 以格式化字符串的形式获取经过的时间
- 如何在C++中检查经过的时间和分配的内存
- 在visualc++2010中经过的时间
- 如何在没有计时器的情况下确定经过了多少时间
- 如何获得自SFML中按下键以来经过的时间
- 两个时间之间经过的时间,格式为24小时hh:mm:ss
- 如何从steady_clock返回经过的时间作为原始数据类型(double)
- 查找经过的时间
- 在经过时间后做某事C++SFML 2