我想得到我系统的当前时间.为此,我在C中使用以下代码:
time_t now;
struct tm *mytime = localtime(&now);
if ( strftime(buffer, sizeof buffer, "%X", mytime) )
{
printf("time1 = \"%s\"\n", buffer);
}
Run Code Online (Sandbox Code Playgroud)
问题是这段代码给出了一些随机时间.此外,随机时间每次都不同.我想要我系统的当前时间.
我有一个包含#include <dos.h>标题的C程序.它显示编译时错误.我知道dos.h头文件在Linux中无效.
dos.h在Linux中是否还有其他等效标头?
我正在学习C程序.当尝试运行代码时,我收到错误:[错误] ld返回1退出状态
#include <stdio.h>
#include <time.h>
void main()
{
time_t t;
time(&t);
clrscr();
printf("Today's date and time : %s",ctime(&t));
getch();
}
Run Code Online (Sandbox Code Playgroud)
谁能解释一下我在这里做错了什么?
我试过这段代码:
int main()
{
printf("Today's date and time : %s \n", gettime());
return 0;
}
char ** gettime() {
char * result;
time_t current_time;
current_time = time(NULL);
result = ctime(¤t_time);
return &result;
}
Run Code Online (Sandbox Code Playgroud)
但仍然显示错误为:错误:被叫对象'1'不是current_time = time(NULL)中的函数; 线.代码有什么问题