mirror of
https://github.com/JamesonHuang/OpenWrt_Luci_Lua.git
synced 2025-06-22 19:10:38 +00:00
add test code about c & sh
This commit is contained in:
BIN
1_3.test_code/c_test/testTimeStamp/test
Executable file
BIN
1_3.test_code/c_test/testTimeStamp/test
Executable file
Binary file not shown.
46
1_3.test_code/c_test/testTimeStamp/test.cpp
Normal file
46
1_3.test_code/c_test/testTimeStamp/test.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
/*************************************************************************
|
||||
> File Name: test.cpp
|
||||
> Description:
|
||||
> Conclusion:
|
||||
> Author: rh_Jameson
|
||||
> Created Time: 2015年07月15日 星期三 15时52分24秒
|
||||
************************************************************************/
|
||||
/* 微秒 */
|
||||
|
||||
#include<stdio.h>
|
||||
#include <sys/time.h>
|
||||
#include<time.h>
|
||||
int main()
|
||||
{
|
||||
struct timeval t_val;
|
||||
gettimeofday(&t_val, NULL);
|
||||
printf("start, now, sec=%d m_sec=%d \n", t_val.tv_sec, t_val.tv_usec);
|
||||
long sec = t_val.tv_sec;
|
||||
time_t t_sec = (time_t)sec;
|
||||
printf("date:%s", ctime(&t_sec));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*纳秒
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
struct timespec time1 = {0, 0};
|
||||
clock_gettime(CLOCK_REALTIME, &time1);
|
||||
printf("CLOCK_REALTIME: %ld, %ld\n", time1.tv_sec, time1.tv_nsec);
|
||||
time_t tmp = time1.tv_sec * 1000000000 + time1.tv_nsec;
|
||||
printf("CLOCK_REALTIME: %ld\n", tmp);
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &time1);
|
||||
printf("CLOCK_MONOTONIC: %ld, %ld\n", time1.tv_sec, time1.tv_nsec);
|
||||
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1);
|
||||
printf("CLOCK_PROCESS_CPUTIME_ID: %ld, %ld\n", time1.tv_sec, time1.tv_nsec);
|
||||
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &time1);
|
||||
printf("CLOCK_THREAD_CPUTIME_ID: %ld, %ld\n", time1.tv_sec, time1.tv_nsec);
|
||||
|
||||
printf("%ld\n", time(NULL));
|
||||
}
|
||||
*/
|
BIN
1_3.test_code/c_test/testTimeStamp/testTimeStamp
Executable file
BIN
1_3.test_code/c_test/testTimeStamp/testTimeStamp
Executable file
Binary file not shown.
95
1_3.test_code/c_test/testTimeStamp/testTimeStamp.c
Normal file
95
1_3.test_code/c_test/testTimeStamp/testTimeStamp.c
Normal file
@ -0,0 +1,95 @@
|
||||
/*************************************************************************
|
||||
> File Name: testTimeStamp.c
|
||||
> Description:
|
||||
> Conclusion:
|
||||
> Author: rh_Jameson
|
||||
> Created Time: 2015年07月14日 星期二 13时05分04秒
|
||||
************************************************************************/
|
||||
/*
|
||||
#include<stdio.h>
|
||||
#include<time.h>
|
||||
int main()
|
||||
{
|
||||
time_t rawtime;
|
||||
time ( &rawtime );
|
||||
printf("%ld\n", &rawtime);
|
||||
printf ( "The current local time is: %s", ctime (&rawtime) );
|
||||
}
|
||||
*/
|
||||
/* ctime example
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
int main ()
|
||||
{
|
||||
time_t time_stp;
|
||||
time ( &time_stp );
|
||||
printf("%ld\n", time_stp);
|
||||
printf ( "The current local time is: %s", ctime (&time_stp) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
/* 用time()取得时间(秒数),利用localtime()
|
||||
|
||||
转换成struct tm 再利用mktine()将struct tm转换成原来的秒数*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <time.h>
|
||||
/*
|
||||
int main()
|
||||
|
||||
{
|
||||
|
||||
time_t timep;
|
||||
|
||||
struct tm *p;
|
||||
|
||||
time(&timep);
|
||||
|
||||
//printf("time() : %d \n",timep);
|
||||
|
||||
p=localtime(&timep);
|
||||
|
||||
timep = mktime(p);
|
||||
|
||||
printf("time()->localtime()->mktime():%d\n",timep);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
#include<stdio.h>
|
||||
#include<sys/time.h>
|
||||
|
||||
#include<unistd.h>
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
/*
|
||||
struct timeval tv;
|
||||
struct timezone tz;
|
||||
gettimeofday(&tv,&tz);
|
||||
|
||||
printf("tv_sec:%ld\n",tv.tv_sec);
|
||||
printf("tv_usec:%ld\n",tv.tv_usec);
|
||||
printf("tz_minuteswest:%d\n",tz.tz_minuteswest);
|
||||
printf("tz_dsttime:%d\n",tz.tz_dsttime);
|
||||
*/
|
||||
struct timeval tpstart,tpend;
|
||||
long iTimeInterval;
|
||||
gettimeofday(&tpstart,NULL);
|
||||
/* to do what you want*/
|
||||
gettimeofday(&tpend,NULL);
|
||||
iTimeInterval=1000000 * (tpend.tv_sec - tpstart.tv_sec);
|
||||
iTimeInterval += tpend.tv_usec - tpstart.tv_usec;
|
||||
/*iTimeInterval 就是微妙级的时间跨度*/
|
||||
printf("tpstart:%ld\n", tpstart.tv_usec);
|
||||
printf("tpend:%ld\n", tpend.tv_usec);
|
||||
printf("iTimeInterval:%ld\n", tpend);
|
||||
|
||||
}
|
Reference in New Issue
Block a user