#include <timeh>
#include <stdioh>
int main( void )
{
time_t t = time(0);
char tmp[64];
strftime( tmp, sizeof(tmp), "%Y/%m/%d %X %A 本年第%j天 %z",localtime(&t) );
puts( tmp );
return 0;
}
size_t strftime(char strDest, size_t maxsize, const char format, const struct tm timeptr);
例如:
#include <stdioh>
#include <timeh>
int main(){
time_t t;
struct tm timeinfo;
time(&t);
timeinfo = localtime ( &t );
printf ( "The current date/time is: %s", asctime (timeinfo) );
return 0;
}
调用DOS date time 命令显示 日期和时间也可以:
system("date /T"); system("time /T");
#include
#include
void
main()
{
time_t
ltime;
struct
tm
today;
time(
<ime
);
today
=
localtime(
<ime
);
printf("%04d-%02d-%02d
%02d:%02d:%02d\n",1900+today->tm_year,today->tm_mon+1,today->tm_mday,today->tm_hour,today->tm_min,today->tm_sec);
}
先调用time获得当前时间,这是个从1970-1-1午夜0点开始的秒数,然后调用localtime将该时间专为本地时间就可以打印了。其中tm_year需要加上1900,tm_mon需要加上1,看printf你就明白了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)