c - 将毫秒添加到 C 日期

标签 c milliseconds strptime

我已经用 strptime 在 C 中解析了一个日期。

现在我有这样的东西:

debugLog(DEB_INFO, "observationDateConverted: %d-%d-%d %d:%d:%d\n", 
                        result.tm_year+1900, 
                        result.tm_mon + 1, 
                        result.tm_mday, 
                        result.tm_hour, 
                        result.tm_min, 
                        result.tm_sec);

在结果中收到最新日期(struct tm)

我有一堆这样的毫秒数:1396682344000 我想将其添加到该日期以了解结束日期。

我应该如何进行?

最佳答案

一般做法:将struct tm转为时间戳(64bit int),然后加上millis/1000。

time_t totalseconds = mktime(&result) + (millis / 1000);

然后您可以使用 C's time API 中的函数将时间戳转换回 struct tm

关于c - 将毫秒添加到 C 日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22833702/

相关文章:

c - 从C程序中的子程序返回数组

python - 无法转换或理解奇怪格式的日期

python - 在 Google App Engine Python 运行时中解析从字符串到日期时间的 UTC 偏移量

c - strptime 时间转换 - 年和月的值错误

c - 如何使用 MinGW 在 Windows 上使用 OpenSSL 编译程序

c - 在linux环境下使用C语言的readahead系统调用

java - SimpleDateFormat 无法解析的日期异常

.net - 为什么 TimeSpan.Milliseconds 的计算结果为 0?

php - php中以毫秒为单位的时差计算

c - 使用 openssl 在 stdout 上打印 RSA 加密文本