gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-28 23:28:08 29 4
gpt4 key购买 nike

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

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com