c++ - 如何获取当前日期和时间?

标签 c++ time

如何获取当前日期 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/

相关文章:

c++ - 如果我的结构中有堆分配的成员,我是否必须在堆中分配结构本身?

c++ - 如何找到包含在类型库中的接口(interface)的接口(interface) ID?

c++ - 带有函数签名的 Const 关键字

java - 分离日期和时间对象

c++ - 如何将时间转换为纪元时间?

python - 将 HH :MM:SS. 微字符串转换为微秒?

c++ - 将 STL 字符串数组转换为 const char* 数组的最有效方法是什么?

c++ - 错误: no matching function for call to 'function namel'

c++ - 将 int64_t 转换为 time_duration

c++ - 自从在 C++ 中执行以来耗时的最干净和最简单的方法