预览加载中,请您耐心等待几秒...
1/4
2/4
3/4
4/4

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

linuxÏ»ñȡϵͳʱ¼äµÄ·½·¨ http://os.51cto.com2009-11-1110:22chinaitlabchinaitlabÎÒÒªÆÀÂÛ() ÕªÒª£º ±êÇ©£ºlinuxϵͳʱ¼ä²Ù×÷ϵͳ Oracle°ïÄú׼ȷ¶´²ì¸÷¸öÎïÁ÷»·½Ú ¿ÉÒÔÓÃlocaltimeº¯Êý·Ö±ð»ñÈ¡ÄêÔÂÈÕʱ·ÖÃëµÄÊýÖµ¡£ LinuxÏ»ñµÃϵͳʱ¼äµÄCÓïÑÔµÄʵÏÖ·½·¨£º 1.¿ÉÒÔÓÃlocaltimeº¯Êý·Ö±ð»ñÈ¡ÄêÔÂÈÕʱ·ÖÃëµÄÊýÖµ¡£ #include<time.h>//CÓïÑÔµÄÍ·Îļþ #include<stdio.h>//CÓïÑÔµÄI/O voidmain() { time_tnow;//ʵÀý»¯time_t½á¹¹ structtm*timenow;//ʵÀý»¯tm½á¹¹Ö¸Õë time(&now); //timeº¯Êý¶ÁÈ¡ÏÖÔÚµÄʱ¼ä(¹ú¼Ê±ê׼ʱ¼ä·Ç±±¾©Ê±¼ä)£¬È»ºó´«Öµ¸ønow timenow=localtime(&now); //localtimeº¯Êý°Ñ´ÓtimeÈ¡µÃµÄʱ¼änow»»Ëã³ÉÄãµçÄÔÖеÄʱ¼ä(¾ÍÊÇÄãÉèÖõĵØÇø) printf("Localtimeis%s\n",asctime(timenow)); //ÉϾäÖÐasctimeº¯Êý°Ñʱ¼äת»»³É×Ö·û£¬Í¨¹ýprintf()º¯ÊýÊä³ö } ×¢ÊÍ£ºtime_tÊÇÒ»¸öÔÚtime.hÖж¨ÒåºÃµÄ½á¹¹Ìå¡£¶øtm½á¹¹ÌåµÄÔ­ÐÎÈçÏ£º structtm { inttm_sec;//seconds0-61 inttm_min;//minutes1-59 inttm_hour;//hours0-23 inttm_mday;//dayofthemonth1-31 inttm_mon;//monthssincejan0-11 inttm_year;//yearsfrom1900 inttm_wday;//dayssinceSunday,0-6 inttm_yday;//dayssinceJan1,0-365 inttm_isdst;//DaylightSavingtimeindicator }; 2.¶ÔijЩÐèÒª½Ï¸ß¾«×¼¶ÈµÄÐèÇó£¬LinuxÌṩÁËgettimeofday()¡£ #include<stdio.h> #include<stdlib.h> #include<sys/time.h> intmain(intargc,char**argv) { structtimstart,stop,diff; gettimeofday(&start,0); //×öÄãÒª×öµÄÊÂ... gettimeofday(&stop,0); tim_subtract(&diff,&start,&stop); printf("×ܼÆÓÃʱ:%dºÁÃë\n",diff.tv_usec); } inttim_subtract(structtim*result,structtim*x,structtim*y) { intnsec; if(x->tv_sec>y->tv_sec) return-1; if((x->tv_sec==y->tv_sec)&&(x->tv_usec>y->tv_usec)) return-1; result->tv_sec=(y->tv_sec-x->tv_sec); result->tv_usec=(y->tv_usec-x->tv_usec); if(result->tv_usec<0) { result->tv_sec--; result->tv_usec+=1000000; } return0; } ±¾ÎĽ²ÊöÈçºÎÔÚLinuxÃüÁîÐÐģʽÏÂÐÞ¸Äϵͳʱ¼äµÄ·½·¨¡£ ʹÓÃdateÃüÁî¿ÉÒÔÔÚLinuxÃüÁîÐÐģʽϲ鿴»òÐÞ¸ÄϵͳÈÕÆÚºÍʱ¼ä¡£ date//ÏÔʾµ±Ç°ÈÕÆÚ date-s//ÉèÖõ±Ç°Ê±¼ä£¬Ö»ÓÐrootȨÏÞ²ÅÄÜÉèÖã¬ÆäËûÖ»Äܲ鿴¡£ date-s20061010//ÉèÖóÉ20061010£¬