如何在C++中保存带有日期和时间的图像文件名?

How to save an image filename with Date & time in C++?

本文关键字:日期 时间的图像 文件名 C++ 保存      更新时间:2023-10-16

我正在使用代码保存相机中的图像,但我需要使用当前拍摄图像的日期和时间保存文件名。我该怎么做?我已经从互联网上尝试了许多不同的代码,但我总是遇到很多错误,编程不是我的强项。任何建议或帮助将不胜感激。这是代码:https://github.com/stereolabs/zed-save-depth/blob/master/src/main.cpp

您可以使用:

    #include <time.h>

为了时间。要获取当前时间:

    time_t current_time = clock();

要获取当前日期,您可以使用:

    struct tm *localtime(const time_t *time);

它返回一个本地时间的结构,如下所示:

    struct tm {
      int tm_sec;   // seconds of minutes from 0 to 61
      int tm_min;   // minutes of hour from 0 to 59
      int tm_hour;  // hours of day from 0 to 24
      int tm_mday;  // day of month from 1 to 31
      int tm_mon;   // month of year from 0 to 11
      int tm_year;  // year since 1900
      int tm_wday;  // days since sunday
      int tm_yday;  // days since January 1st
      int tm_isdst; // hours of daylight savings time
    }