标签:style blog io ar color sp div log bs
linux
#include <stdio.h> #include <time.h> int main(int argc,char **argv) { //两种时间的获取方法 struct timeval tv; gettimeofday(&tv,NULL); time_t t=time(0); printf("%u---%u+++%u\n",tv.tv_sec,tv.tv_usec,t); //时间格式转换 char tmp[64]; strftime(tmp,sizeof(tmp),"%Y%m%d%H%M%S\n",localtime(&t)); printf("%s",tmp); return 0; }
windows
#include <stdio.h> #include <time.h> int main(int argc, char* argv[]) { //windows没有timeval结构,当然也没有gettimeofday函数 //struct timeval tv; //gettimeofday(&tv,NULL); time_t t=time(0); char tmp[64]; strftime(tmp,sizeof(tmp),"%Y%m%d-%H%M%S",localtime(&t)); printf("%s",tmp); return 0; }
标签:style blog io ar color sp div log bs
原文地址:http://www.cnblogs.com/bloodofhero/p/4148079.html