我对此做了一些研究,我有相当令人信服的证据证明
回答YES,回答NO。我不确定该相信哪一方。
首先,我在 cppreference.com 上找到的文档,以及
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4659.pdf似乎对此无话可说。
我认为这是语言环境不支持时区的证据。
但是https://en.cppreference.com/w/cpp/locale/time_get/get和 https://en.cppreference.com/w/cpp/locale/time_put/put
两者都说:
%z writes offset from UTC in the ISO 8601 format (e.g. -0430), or no characters if the time zone information is not available %Z writes time zone name or abbreviation, or no characters if the time zone information is not available (locale dependent)
#include <iostream>
#include <cstdlib>
#include <locale>
#include <sstream>
using namespace std;
int main ()
{
// locale l;
locale l = locale::classic ();
tm when{};
const time_put<char>& tmput = use_facet<time_put<char>> (l);
ostringstream oss;
oss.imbue (l);
static const string kTZOffsetPattern_{"%z"};
tmput.put (oss, oss, ' ', &when, kTZOffsetPattern_.c_str (), kTZOffsetPattern_.c_str () + kTZOffsetPattern_.length ());
cout << oss.str ();
return 0;
}
最佳答案
直接回答您的问题
Does a C++ locale have an associated time zone?
strftime 的规范中说:
%Zis replaced by the locale’s time zone name or abbreviation, or by no characters if no time zone is determinable.[tm_isdst]
struct lconv 的 C 规范不提供此类成员来存储该信息。规范确实允许实现添加这样的成员,但实际上,实现不使用 C 语言环境存储该信息。time_put和 time_get根据 strftime 的 C 规范定义自己, strptime 的 POSIX 规范,以及一些不包含时区名称或缩写的附加内容。strftime 的 POSIX 规范比 C 规范详细得多,并删除了与“语言环境”的关联:
ZReplaced by the timezone name or abbreviation, or by no bytes if no timezone information exists.[ tm_isdst]
struct lconv 的 POSIX 规范也比 C 规范详细得多,但仍不提供时区名称或缩写的存储。%z ) 和时区缩写 ( %Z ) 可能可用,但将作为本地时区数据的一部分存储,而不是与当前区域设置数据一起存储,主要是因为没有好的时区和语言环境之间的一对一映射。tm when{};将 tm 的所有成员归零,包括 tm_isdst .当tm_isdst为零,这意味着已知夏令时无效,对于此特定 tm .tm也允许具有标准未指定的成员。一个流行的扩展是拥有成员(member) tm_gmtoff它以秒为单位保存 UTC 偏移量。如果您的 Linux 实现有这样的成员,tm when{};将其设置为 0 秒。如果您的 Windows 实现没有这样的成员,则本地时区的 UTC 偏移量将存储在其他地方。这解释了您所看到的差异,并且两种实现都符合要求。std::chrono::time_zone 的新类型。 . time_zone的成员函数之一是:template<class Duration> sys_info get_info(const sys_time<Duration>& st) const;
sys_time<Duration>只是一个 system_clock::time_point ,但任何精度。所以你给了一个 time_zone time_point ,你会得到一个 sys_info里面包含了各种有用的信息 time_zone在那time_point :struct sys_info
{
sys_seconds begin;
sys_seconds end;
seconds offset;
minutes save;
string abbrev;
};
[begin, end)告诉您此信息在何时有效(这些是 UTC 时间点)。 offset是 time_zone的当前 UTC 偏移量 seconds . save != 0min , time_zone目前被认为是夏令时。 time_zone的当前缩写存储在 abbrev . const time_zone* current_zone();
#include <chrono>
#include <iostream>
int
main()
{
using namespace std::chrono;
std::cout << current_zone()->get_info(system_clock::now()) << '\n';
}
2018-03-11 07:00:00
2018-11-04 06:00:00
-04:00:00
01:00
EDT
date 中而不是 std::chrono .#include "date/tz.h"
#include <chrono>
#include <iostream>
int
main()
{
using namespace date;
using namespace std::chrono;
std::cout << locate_zone("Australia/Sydney")->get_info(system_clock::now()) << '\n';
}
2018-10-06 16:00:00
2019-04-06 16:00:00
11:00:00
01:00
AEDT
关于c++ - C++ 语言环境是否有关联的时区?如果是,您如何访问它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52839648/
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚
Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack
在选择我想要运行操作的频率时,唯一的选项是“每天”、“每小时”和“每10分钟”。谢谢!我想为我的Rails3.1应用程序运行调度程序。 最佳答案 这不是一个优雅的解决方案,但您可以安排它每天运行,并在实际开始工作之前检查日期是否为当月的第一天。 关于ruby-如何每月在Heroku运行一次Scheduler插件?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/8692687/
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为