#include <time.h>
#include <stdio.h>
#include <stdlib.h>
void mytime(const struct tm* ptm){
char str[256];
size_t ret;
ret = strftime(str, 256, "xiaolixi-time:%Y-%m-%d/%H:%M:%S %p wday-%w yday-%j\n", ptm);
if (ret == 0){
fprintf(stderr, "sorry.\n");
}
else{
printf(str);
}
}
int main(){
time_t t;
time_t pt;
struct tm* ptm;
time(&t);
ptm = localtime(&t);
printf("time->char:%s\n", ctime(&t));
printf("tm->char :%s\n", asctime(ptm));
pt = mktime(ptm);
mytime(ptm);
printf("now cpu have run : %d s %d ms\n", clock() / CLOCKS_PER_SEC,clock());
return 0;
}
time.h
最新推荐文章于 2024-05-09 10:16:03 发布