问题标签 [time.h]

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.

0 投票
3 回答
3151 浏览

c - C中两个日期之间的差异

我试图通过使用下面的 C 代码来获得两个日期之间的差异。

但是代码总是给出差异0。帮助我找出我犯错的地方。

我在linux下使用gcc编译器。

编辑: @qchen 的回答对解决我的问题很有帮助。还有一个疑问。以下是我的更新。从答案

tm_year 是自 1900 年以来的年份,那么如果我将 1876 替换为 1876 到 2012 之间的年份,为什么我会得到正确的输出。

0 投票
3 回答
698 浏览

c - 这个程序中的ctime函数是如何工作的?

我正在发布一个我遇到的程序。谁能解释我

  1. “0x7FFFFFFF”是什么意思?
  2. ctime() 函数是如何工作的?

0 投票
1 回答
1194 浏览

c++ - C++ 未定义对在代码中实现和模板化的函数的引用

首先,我试图调用的函数不在外部库中。它是以下内容的一部分(我正在回到 C++,所以我想我会从编写自己的 cron 守护程序实现开始)

这是我的代码:

这是我尝试编译它时得到的结果:

我究竟做错了什么?

0 投票
3 回答
3251 浏览

c - 时钟()在C中返回一个负值

我正在使用一个非常简单的代码来测量执行时间。它运行良好,直到我不确定可能不超过 20 分钟。但之后(> 20 分钟。)它返回负面结果。我搜索了整个论坛和尝试了所有方法,例如更改数据类型,使用 long unsigned (返回 0)但再次失败。以下是我的代码片段

输出是 ARM 所用时间仅为-2055.367296

任何帮助表示赞赏,在此先感谢。

0 投票
1 回答
54 浏览

c++ - Strange behaviour from references in an output stream

I have noticed strange behaviour when printing output to a stream. My code loops through a large dataset and, amongst other things, reads a timestamp from each item. The timestamp from the first item is stored so an elapsed time can be calculated.

The output printed to screen shows the same time printed twice e.g:

But if split the print line into two:

I get the expected output:

The only change between the two outputs was to the cout line(s). This is easy enough to work around but I'd like to understand what's happening.

0 投票
0 回答
690 浏览

c - localtime 返回看到 tm_wday 不一致的结果

不确定这是否是时区问题:目前在 SGT 上。

以下代码将 2009 年 4 月 17 日星期五报告为第 6 周 (??),但将 1 月 2 日星期五报告为第 5 周。

f19 3.11.4-201.fc19.x86_64,gcc 4.8.1 / clang 3.3

提前谢谢你。

迈克尔

0 投票
2 回答
716 浏览

c - C 时差

我试图在 C 中区分两个日期,但我收到这样的输出:

未来日期:18-11-2013 22:8

当前日期:18-11-2013 22:8

这是我的代码:

0 投票
2 回答
1395 浏览

c - 使用clock()的延迟函数

我写了一个延迟函数并用这段代码对其进行了测试,但是在标准输出中我没有看到任何数字。

然后我像这样更改了 printf() 调用:

有趣的是,它奏效了。我也尝试过这样的无延迟功能:

它也奏效了。我在这里想念什么?为什么我在运行第一个代码时看不到任何数字?感谢您的帮助:)

0 投票
2 回答
1951 浏览

c - difftime 在 MinGW 中返回不正确的值

我正在尝试计算两者之间的差异time_t
difftime返回它的第一个参数而不是差异!
我的代码是:

它打印:

我正在编译GCC(in MinWG)有
什么问题?

0 投票
1 回答
17321 浏览

mysql - C - 如何将 time_t 转换为 tm?

我有一个使用time_t数据类型的变量。我想将此类型转换为“YYYY-MM-DD HH:MM:SS”。我只知道它是否仅适用于localtime()示例:

任何建议如何转换它?因为我的时间总是每分钟都在增加,而不是像localtime(). 我需要这种转换来匹配datetimeMySQL 数据库中的类型。