int _tmain(int argc, _TCHAR* argv[])
{
int i = 0;
/*time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime( &rawtime );
printf ( "Current local time and date: %s", asctime (timeinfo) );*/
//sprintf();
time_t tt = time(0);
//产生“YYYY-MM-DD hh:mm:ss”格式的字符串。
char s[32];
i = strftime(s, sizeof(s), "%Y-%m-%d %H:%M:%S", localtime(&tt));
printf("\n i= %d\n",i);
//s[i] = '\n';
s[31] = '\n';
printf("%s\n",s);
return 0;
}
time.h中函数原型
_CRTIMP size_t __cdecl strftime(_Out_writes_z_(_SizeInBytes) char * _Buf, _In_ size_t _SizeInBytes, _In_z_ _Printf_format_string_ const char * _Format, _In_ const struct tm * _Tm);
写不超过_SizeInBytes个数个字节,返回实际写进Buf