- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
问题是:
代码:
boost::local_time::local_date_time currentTime(
boost::posix_time::second_clock::local_time(),
boost::local_time::time_zone_ptr());
std::cout << currentTime.local_time() << std::endl;
代码:
tzset();
// the var tzname will have time zone names
// the var timezone will have the current offset
// the var daylight should show me if there is daylight "on"
但我仍然无法获得当前时区的 local_date_time...有人知道该怎么做吗?
最佳答案
好吧,至于现在我还不知道完整的答案
但是有代码可以帮助打印当前时区偏移量
(基于此处相关问题的答案(stackoverflow)和一些内部 boost 代码)
我绝对不确定它是否能在所有机器上正常工作,但现在总比没有好:
boost::posix_time::time_duration getUtcOffset(const boost::posix_time::ptime& utcTime)
{
using boost::posix_time::ptime;
const ptime localTime = boost::date_time::c_local_adjustor<ptime>::utc_to_local(utcTime);
return localTime - utcTime;
}
std::wstring getUtcOffsetString(const boost::posix_time::ptime& utcTime)
{
const boost::posix_time::time_duration td = getUtcOffset(utcTime);
const wchar_t fillChar = L'0';
const wchar_t timeSeparator = L':';
std::wostringstream out;
out << (td.is_negative() ? L'-' : L'+');
out << std::setw(2) << std::setfill(fillChar)
<< boost::date_time::absolute_value(td.hours());
out << L':';
out << std::setw(2) << std::setfill(fillChar)
<< boost::date_time::absolute_value(td.minutes());
return out.str();
}
int main()
{
const boost::posix_time::ptime utcNow =
boost::posix_time::second_clock::universal_time();
const std::wstring curTimeOffset = getUtcOffsetString(utcNow);
std::wcout << curTimeOffset.c_str() << std::endl; // prints -05:00 on my comp
}
关于c++ - boost:从机器获取带有当前时区的当前 local_date_time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8746848/
我正在使用 Boost's datetime library在我的项目中。当我发现它具有小时、天、月、年等持续时间类型时,我感到非常高兴,并且它们会根据您将它们添加到的内容更改它们的值(即添加 1 个
问题是: 我知道如何在 boost 中获取本地时间 代码: boost::local_time::local_date_time currentTime( boost::pos
我正在使用 boost date_time 库在我的应用程序中开发过滤方案。假设我有 10000 条记录,每条记录都包含一个时间戳(UTC 中的毫秒)。我想使用 boost 将此时间戳转换为给定的时区
我有: time_t dataFromTodayByAddingYearsMonthsDays(int years, int months, int days) { using
如何从 tm 时间结构创建一个 boost::local_time::local_date_time 对象? 最佳答案 有点痛苦,但看起来你必须通过 posix_time::ptime: using
我尝试将 boost local_date_time 转换为 UTC,但我对 utc_time() 的返回时间感到困惑。这是一个简化的代码: #include "boost/date_time/loc
我有一个与不同时区有关的问题。有一个文件存储本地开始和结束时间。例如第一个条目在纽约时区,而第二个条目在香港时区。 80000-150000 100000-180000 所以我尝试使用 boost::
我是一名优秀的程序员,十分优秀!