localtime.c
#include<stdio.h>
#include<time.h>
main()
{
time_t temp;
struct tm* p;
time(&temp);
p = localtime(&temp);
printf("year %d\n",p->tm_year+1900);
printf("month %d\n",p->tm_mon+1);
printf("day %d\n",p->tm_mday);
printf("hour %d\n",p->tm_hour);
printf("minute %d\n",p->tm_min);
printf("second %d\n",p->tm_sec);
printf("weekday %d\n",p->tm_wday);
}
time.c
#include<stdio.h>
#include<time.h>
int main()
{
time_t s;
s=time((time_t*)NULL);
printf("now %ld",s);
return 0;
}
gettime.c
#include<stdio.h>
#include<time.h>
main()
{
time_t temp;
struct tm* p;
time(&temp);
p = gmtime(&temp);
printf("year %d\n",p->tm_year+1900);
printf("month %d\n",p->tm_mon+1);
printf("day %d\n",p->tm_mday);
printf("hour %d\n",p->tm_hour);
printf("minute %d\n",p->tm_min);
printf("second %d\n",p->tm_sec);
printf("weekday %d\n",p->tm_wday);
}
ctime.c
#include<stdio.h>
#include<time.h>
int main()
{
time_t temp;
char *ti;
time(&temp);
ti=ctime(&temp);
printf("%s\n",ti);
return 0;
}
mktime.c
#include<stdio.h>
#include<time.h>
int main()
{
time_t temp1,temp2;
char *ti1, *ti2;
struct tm *p;
time(&temp1);
ti1=ctime(&temp1);
printf("%s\n",ti1);
p=gmtime(&temp1);
temp2=mktime(p);
ti2 = ctime(&temp2);
printf("%s\n",ti2);
return 0;
}
runtime.c
#include<stdio.h>
#include<time.h>
#include<sys/time.h>
#include<unistd.h>
int main()
{
struct timeval tv1,tv2;
struct timezone tz1,tz2;
long sec,usec,i;
gettimeofday(&tv1,&tz1);
for(i=1;i<1000;i++)
gettimeofday(&tv2,&tz2);
sec = tv2.tv_sec-tv1.tv_sec;
usec = tv2.tv_usec-tv1.tv_usec;
printf("%ld \n",1000000*sec+usec);
return 0;
}
inbetweenout.c
#include<stdio.h>
#include<time.h>
#include<sys/time.h>
#include<unistd.h>
int main()
{
struct timeval tv1,tv2;
struct timezone tz1,tz2;
int sec;
long usec,i;
gettimeofday(&tv1,&tz1);
printf("please input a int number\n");
scanf("%ld",&i);
gettimeofday(&tv2,&tz2);
sec = tv2.tv_sec-tv1.tv_sec;
usec = tv2.tv_usec-tv1.tv_usec;
printf("%d\n",sec);
printf("%ld \n",usec);
return 0;
}
asctime.c
#include<stdio.h>
#include<time.h>
int main()
{
time_t temp;
struct tm * p;
char *ti;
time(&temp);
p=gmtime(&temp);
ti=asctime(p);
printf("%s\n",ti);
return 0;
}