23,222
社区成员
发帖
与我相关
我的任务
分享
#include <sys/time.h>
#include <stdio.h>
#include <time.h>
int
main(int argc, char *argv[])
{
struct timeval tv;
struct tm *tp;
char buf[28];
size_t len;
gettimeofday(&tv, NULL);
tp = localtime(&tv.tv_sec);
len = strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tp);
snprintf(buf + len, sizeof(buf) - len, ".%06d", (int)tv.tv_usec);
printf("%s\n", buf);
return 0;
}
#include <stdio.h>
#include <time.h>
int main(void)
{
time_t now;
struct tm *timenow;
time(&now);
timenow=localtime(&now);
printf("Curent Time is:%s\n",asctime(timenow));
return 0;
}
~
time_t now;
struct tm *timenow;
time(&now);
timenow = localtime(&now);
ostringstream tstr;
tstr << "[" <<timenow->tm_hour<<":"<<timenow->tm_min<<":"<<timenow->tm_sec << "]" ;