当前位置: 技术问答>linux和unix
在LINUX下用C++编程,如何获取系统当前的时间。
来源: 互联网 发布时间:2016-02-07
本文导语: 我用C++在LINUX下编写一个日志的操作,用什么函数可以获取系统的当前时间,怎么使用! | #include "stdio.h" #include "time.h" void main () { time_t t; struct tm * a; time(&t); a=localtime(&t)...
我用C++在LINUX下编写一个日志的操作,用什么函数可以获取系统的当前时间,怎么使用!
|
#include "stdio.h"
#include "time.h"
void main ()
{ time_t t;
struct tm * a;
time(&t);
a=localtime(&t);
printf("%4d-%02d-%02d %02d:%02d:%02dn",1900+a->tm_year,1+a->tm_mon,a->tm_mday,a->tm_hour,a->tm_min,a->tm_sec);
return 0;
}
#include "time.h"
void main ()
{ time_t t;
struct tm * a;
time(&t);
a=localtime(&t);
printf("%4d-%02d-%02d %02d:%02d:%02dn",1900+a->tm_year,1+a->tm_mon,a->tm_mday,a->tm_hour,a->tm_min,a->tm_sec);
return 0;
}
|
#include
#include
int main ()
{
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
printf ( "The current time is: %d:%d:%d", timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec );
return 0;
}
#include
int main ()
{
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
printf ( "The current time is: %d:%d:%d", timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec );
return 0;
}
|
#include
main()
{
time_t timep;
time (&timep);
printf(“%s”,ctime(&timep));
}
main()
{
time_t timep;
time (&timep);
printf(“%s”,ctime(&timep));
}