c++ - Windows 上的 strptime() 等价物?

标签 c++ c windows datetime

是否有适用于 Windows 的 strptime() 的良好等效实现?不幸的是,这个 POSIX 函数似乎不可用。

Open Group description of strptime - 摘要:它将文本字符串如 "MM-DD-YYYY HH:MM:SS" 转换为 tm struct,与 strftime() 相反.

最佳答案

如果您不想移植任何代码或谴责您的项目进行提升,您可以这样做:

  1. 使用 sscanf
  2. 解析日期
  3. 然后将整数复制到 struct tm 中(从月份减去 1,从年份减去 1900——月份是 0-11,年份从 1900 开始)
  4. 最后,使用 mktime 得到一个 UTC 纪元整数

请记住将 struct tmisdst 成员设置为 -1,否则您将遇到夏令时问题。

关于c++ - Windows 上的 strptime() 等价物?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/321849/

相关文章:

c - 是否有一个用 C 编写的分词器函数可以完成 boost::escaped_list_separator 的功能?

c - C 中的脚本未正确添加 float

windows - 私有(private)字节的 win32 API 函数是什么?

.net - 什么用于重复性(每日、每周、每月)任务?工作流、Windows 服务,还是其他?

windows - Jenkins 管道 : Get value from ini file

c++ - 包含 .h 时 CUDA 报告 Unresolved inclusion

c++ - 使用 GLM 库在 OpenGL 中绘制顶点时如何使用常规坐标系

python - 无法获得新的 tf.Operation 在 Tensorflow 的 Python shell 中工作

c++ - fopen 函数中的 a 和 a+ 选项有什么区别?

我们可以将这个嵌套循环finding_indice 转换为递归吗?