我想要获取我的系统的当前时间.为此,我在C中使用以下代码:
time_t now;
struct tm *mytime = localtime(&now);
if ( strftime(buffer, sizeof buffer, "%X", mytime) )
{
printf("time1 = \"%s\"\n", buffer);
}
问题是这段代码给出了一些随机时间.而且,随机时间每次都不一样.我想要系统的当前时间.
我想要获取我的系统的当前时间.为此,我在C中使用以下代码:
time_t now;
struct tm *mytime = localtime(&now);
if ( strftime(buffer, sizeof buffer, "%X", mytime) )
{
printf("time1 = \"%s\"\n", buffer);
}
问题是这段代码给出了一些随机时间.而且,随机时间每次都不一样.我想要系统的当前时间.
从here粘贴的副本:
/* localtime example */
#include <stdio.h>
#include <time.h>
int main ()
{
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
printf ( "Current local time and date: %s", asctime (timeinfo) );
return 0;
}
(只需在main()
个参数列表中添加void
个参数,就可以在C中使用)