问题标签 [time-t]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c++ - 假设 time_t 以秒为单位有多安全?
我正在对时间进行大量计算,通过添加秒来构建相对于其他时间对象的时间对象。该代码应该在嵌入式设备和服务器上运行。大多数文档都说time_t
它是某种算术类型,通常存储自纪元以来的时间。假设time_t
从某事开始存储几秒钟有多安全?如果我们可以假设,那么我们可以只使用加法和减法而不是localtime
,mktime
和difftime
。
到目前为止,我已经通过使用 a 解决了这个问题,表示假设使用秒constexpr bool time_tUsesSeconds
是否安全。time_t
如果假设time_t
在几秒钟内是不可移植的,有没有办法自动初始化该常量?
c - strtoul 从字符串日期(“03/10/2013 14:01:00”)转换为 time_t
我不明白,为什么这不起作用?PS:我从一些谷歌找到了这段代码!
问题:我不知道为什么它应该工作?这是否也考虑时区?!
c++ - gsoap complexTtype containing a complexType
For a project, i have to write a gsoap client on a Windows platform. I'm using MinGw g++. I have generated the code using the -j option in order to receive the soap...Proxy.h and .cpp files
I want to send a request to our web service, where the input (ns2_getSMSByTimeSpan) and the response (ns2_getSMSByTimeSpanResult) parameters are both complex types. The input parameter contains another complexType (ns2__TimeSpan), which consists of 2 time_t variables. In the wsdl it's defined as xsd:dateTime. I try - and fail - to set those 2 time_t variables. I just don't know how to access it. The comments in the generated files didn't really help me and i also couldn't find an answer by googling.
This is what the classes ns2_getSMSByTimeSpan and ns2__TimeSpan look like in soapStub.h
What i'm doing so far: I'm creating an instance of the gsoap class and create and instantiate the complexTypes i want to use.
Then i try to set the smsByTimeSpan->TimeSpan->StartDate value, but whatever approach i try, the client crashes:
Can anybody please tell me, what i do wrong? Or well, tell me how i correctly input data into the timeSpan->StartDate value?
Thanks in advance
mysql - C - 如何将 time_t 转换为 tm?
我有一个使用time_t
数据类型的变量。我想将此类型转换为“YYYY-MM-DD HH:MM:SS”。我只知道它是否仅适用于localtime()
示例:
任何建议如何转换它?因为我的时间总是每分钟都在增加,而不是像localtime()
. 我需要这种转换来匹配datetime
MySQL 数据库中的类型。
.net - 将 std::time_t 转换为 System::DateTime 的标准一致方法?
我已经找到了几个与将std::time_t
值相互转换相关的答案System::DateTime
。但是,几乎所有答案似乎都忽略std::time_t
了标准中实际上未定义的类型。大多数解决方案只是强制std::time_t
转换为任何需要的对象或将算术运算应用于std::time_t
可能的对象,因为它是算术类型,但没有关于此类运算结果的规范。我知道大多数编译器都定义time_t
为int
某种大小的 an,但仅在最近的许多实现中它已从 更改为 的事实int32
表明int64
,更改确实是可能的。
所以我想出了这个解决方案,它应该适用于任何类型的std::time_t
. 它从我所看到的工作。但我想知道 -有没有我可能不知道的陷阱?
做了3个假设:
- 结果
std::time_t
应该是UTC,因为它不包含任何本地化信息 - 结果
System::DateTime
应该是本地时间,因为System::DateTime::Now
返回一个本地化的DateTime
makeUtcTime
是一个辅助函数std::tm
,根据提供的值创建一个并从中创建一个 UTCstd::time_t
。这目前是使用实现的,_mkgmtime
因为我们的互操作代码可以安全地依赖于 Microsoft 扩展的存在。但是,UTC 版本mktime
在其他编译器中也很容易获得(标准mktime
需要本地时间)。
2个不太重要的事情要考虑:
- 这
const_cast
是必要的,因为 marshal_as-template 需要一个const T&
as 参数,而我无法访问 const .NET 值类型对象的属性。但是,可能有更好的解决方案。 unix_epoch...
东西应该是吗static const
?
(我不确定这是否应该发布在“程序员交流”上,因为它更像是一个讨论,但由于这是一个非常具体的 C++ 问题,我认为 SO 可能是更好的提问场所)
c++ - 以 4 个字节打包时间戳
我的内存使用非常有限。
我需要在我的程序中存储一个日期时间。精度是一秒。一个日期时间值只有 4 个字节。
实现这一目标的最佳方法是什么?
c++ - 如何在当前日期/时间之后命名我创建的文本文件
首先,我对 X++ 的了解很少,我只需要编辑我得到的代码。我有一个 C++ 程序,它创建一个文本文件并在其中存储数据。现在程序正在使用:
但我需要更改此代码,因此每次运行此代码时,它都会创建一个新文件名。我的建议是以某种方式将时间/日期合并为文件名,但我不确定如何执行此操作。我已经尝试过研究,看起来使用time_t
是要走的路,但我不确定如何在我的情况下使用它。
是否可以将时间/日期保存为变量,然后使用:
如果是这样,我将如何处理?
多谢你们
c++ - 在没有 C++ CLI 错误处理的情况下,在 time_t 中转换 DateTime 是否安全?
我想使用下一个代码:
所以问题是:异常安全还是我应该在这里处理一些错误?
我的意思是:在这种情况下从double
(TotalSeconds)转换为安全吗?long long
c - c 特定日期到时间
我想在 C 中从特定日期转换为秒。例如,如果我给出 2015 年 12 月 25 日,它将转换为秒。这是我发现的将当前日期转换为秒的程序。但我想从特定日期转换为秒。
c++ - 如何将 boost local_date_time 转换为 time_t
我有:
我如何将这个增强local_date_time
野兽转换为time_t
?