gpt4 book ai didi

c - 如何使用C编程显示日期时间

转载 作者:行者123 更新时间:2023-11-30 17:15:51 25 4
gpt4 key购买 nike

我必须使用 gettime()getdate() 分别显示日期和时间 >C 编程语言。我编写的代码仅在同一行显示日期和时间。我希望仅使用核心C而不是Windows格式来完成此代码。我使用的编辑器是Visual Studio 2008

下面我发布了我的代码,该代码仅在一行上显示日期时间。

#include "stdafx.h"
#include <conio.h>
#include <stdio.h>
#include <time.h>

char *gettime();
int_main(int argc,_TCHAR* argv[])
{
printf("The time is %s\n",gettime());
getch();
return 0;
}
char *gettime()
{

time_t t;
tm b;
time(&t);
return ctime(&t);

}

最佳答案

您可以使用本地时间/gmtime

struct tm * timeinfo;
timeinfo = localtime (&t);

并根据需要使用tm结构组件,如果您只需要打印日期和时间,也可以使用strfrtime格式函数。

关于c - 如何使用C编程显示日期时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29843744/

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