如何获取当前日期 d/m/y。我需要他们有 3 个不同的变量而不是一个,例如 day=d;月=m;年=y;
.
最佳答案
对于 linux,您可以使用 'localtime'功能。
#include <time.h>
time_t theTime = time(NULL);
struct tm *aTime = localtime(&theTime);
int day = aTime->tm_mday;
int month = aTime->tm_mon + 1; // Month is 0 - 11, add 1 to get a jan-dec 1-12 concept
int year = aTime->tm_year + 1900; // Year is # years since 1900
关于c++ - 如何获取当前日期和时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8343676/