c ms/ºÁÃ뼶 ¼Æʱ ¼°time.h ÆäËüº¯ÊýÏê½â
C/C++ÖеÄÈÕÆÚºÍʱ¼ä
ͻ񻣼
±¾ÎÄ´Ó½éÉÜ»ù´¡¸ÅÄîÈëÊÖ£¬Ì½ÌÖÁËÔÚC/C++ÖжÔÈÕÆÚºÍʱ¼ä²Ù×÷ËùÓõ½µÄÊý¾Ý½á¹¹ºÍº¯Êý£¬²¢¶Ô¼Æʱ¡¢Ê±¼äµÄ»ñÈ¡¡¢Ê±¼äµÄ¼ÆËãºÍÏÔʾ¸ñʽµÈ·½Ãæ½øÐÐÁ˲ûÊö¡£±¾ÎÄ»¹Í¨¹ý´óÁ¿µÄʵÀýÏòÄãչʾÁËtime.hÍ·ÎļþÖÐÉùÃ÷µÄ¸÷ÖÖº¯ÊýºÍÊý¾Ý½á¹¹µÄÏêϸʹÓ÷½·¨¡£
¹Ø¼ü×Ö£º
UTC£¨ÊÀ½ç±ê׼ʱ¼ä£©£¬Calendar Time£¨ÈÕÀúʱ¼ä£©£¬epoch£¨Ê±¼äµã£©£¬clock tick£¨Ê±ÖÓ¼Æʱµ¥Ôª£©
1£®¸ÅÄî
ÔÚC/C++ÖУ¬¶Ô×Ö·û´®µÄ²Ù×÷ÓкܶàÖµµÃ×¢ÒâµÄÎÊÌ⣬ͬÑù£¬C/C++¶Ôʱ¼äµÄ²Ù×÷Ò²ÓÐÐí¶àÖµµÃ´ó¼Ò×¢ÒâµÄµØ·½¡£×î½ü£¬ÔÚ¼¼ÊõȺÖÐÓкܶàÍøÓÑÒ²¶à´ÎÎʵ½¹ýC++ÓïÑÔÖжÔʱ¼äµÄ²Ù×÷¡¢»ñÈ¡ºÍÏÔʾµÈµÈµÄÎÊÌâ¡£ÏÂÃ棬ÔÚÕâƪÎÄÕÂÖУ¬±ÊÕß½«Ö÷Òª½éÉÜÔÚC/C++ÖÐʱ¼äºÍÈÕÆÚµÄʹÓ÷½·¨.
ͨ¹ýѧϰÐí¶àC/C++¿â£¬Äã¿ÉÒÔÓкܶà²Ù×÷¡¢Ê¹ÓÃʱ¼äµÄ·½·¨¡£µ«ÔÚÕâ֮ǰÄãÐèÒªÁ˽âһЩ“ʱ¼ä”ºÍ“ÈÕÆÚ”µÄ¸ÅÄÖ÷ÒªÓÐÒÔϼ¸¸ö£º
Coordinated Universal Time£¨UTC£©£ºÐµ÷ÊÀ½çʱ£¬ÓÖ³ÆΪÊÀ½ç±ê׼ʱ¼ä£¬Ò²¾ÍÊÇ´ó¼ÒËùÊìÖªµÄ¸ñÁÖÍþÖαê׼ʱ¼ä£¨Greenwich Mean Time£¬GMT£©¡£±ÈÈ磬ÖйúÄڵصÄʱ¼äÓëUTCµÄʱ²îΪ+8£¬Ò²¾ÍÊÇUTC+8¡£ÃÀ¹úÊÇUTC-5¡£
Calendar Time£ºÈÕÀúʱ¼ä£¬ÊÇÓÓ´ÓÒ»¸ö±ê׼ʱ¼äµãµ½´ËʱµÄʱ¼ä¾¹ýµÄÃëÊý”À´±íʾµÄʱ¼ä¡£Õâ¸ö±ê׼ʱ¼äµã¶Ô²»Í¬µÄ±àÒëÆ÷À´Ëµ»áÓÐËù²»Í¬£¬µ«¶ÔÒ»¸ö±àÒëϵͳÀ´Ëµ£¬Õâ¸ö±ê׼ʱ¼äµãÊDz»±äµÄ£¬¸Ã±àÒëϵͳÖеÄʱ¼ä¶ÔÓ¦µÄÈÕÀúʱ¼ä¶¼Í¨¹ý¸Ã±ê׼ʱ¼äµãÀ´ºâÁ¿£¬ËùÒÔ¿ÉÒÔ˵ÈÕÀúʱ¼äÊÇ“Ïà¶Ôʱ¼ä”£¬µ«ÊÇÎÞÂÛÄãÔÚÄÄÒ»¸öʱÇø£¬ÔÚͬһʱ¿Ì¶Ôͬһ¸ö±ê׼ʱ¼äµãÀ´Ëµ£¬ÈÕÀúʱ¼ä¶¼ÊÇÒ»ÑùµÄ¡£
epoch£ºÊ±¼äµã¡£Ê±¼äµãÔÚ±ê×¼C/C++ÖÐÊÇÒ»¸öÕûÊý£¬ËüÓôËʱµÄʱ¼äºÍ±ê׼ʱ¼äµãÏà²îµÄÃëÊý£¨¼´ÈÕÀúʱ¼ä£©À´±íʾ¡£
clock tick£ºÊ±ÖÓ¼Æʱµ¥Ôª£¨¶ø²»°ÑËü½Ð×öʱÖӵδð´ÎÊý£©£¬Ò»¸öʱÖÓ¼Æʱµ¥ÔªµÄʱ¼ä³¤¶ÌÊÇÓÉCPU¿ØÖƵġ£Ò»¸öclock tick²»ÊÇCPUµÄÒ»¸öʱÖÓÖÜÆÚ£¬¶øÊÇC/C++µÄÒ»¸ö»ù±¾¼Æʱµ¥Î»¡£
ÎÒÃÇ¿ÉÒÔʹÓÃANSI±ê×¼¿âÖеÄtime.hÍ·Îļþ¡£Õâ¸öÍ·ÎļþÖж¨ÒåµÄʱ¼äºÍÈÕÆÚËùʹÓõķ½·¨£¬ÎÞÂÛÊÇÔڽṹ¶¨Ò壬»¹ÊÇÃüÃû£¬¶¼¾ßÓÐÃ÷ÏÔµÄCÓïÑÔ·ç¸ñ¡£ÏÂÃ棬ÎÒ½«ËµÃ÷ÔÚC/C++ÖÐÔõÑùʹÓÃÈÕÆÚµÄʱ¼ä¹¦ÄÜ¡£
2£® ¼Æʱ
C/C++ÖеļÆʱº¯ÊýÊÇclock()£¬¶øÓëÆäÏà¹ØµÄÊý¾ÝÀàÐÍÊÇclock_t¡£ÔÚMSDNÖУ¬²éµÃ¶Ôclockº¯Êý¶¨ÒåÈçÏ£º
clock_t clock( void );
Õâ¸öº¯Êý·µ»Ø´Ó“¿ªÆôÕâ¸ö³ÌÐò½ø³Ì”µ½“³ÌÐòÖе÷ÓÃclock()º¯Êý”ʱÖ
Ïà¹ØÎĵµ£º
C²Ù×÷·ûµÄÓÅÏȼ¶ºÍ¹ØÁª¹æÔò
²Ù×÷·û
¹ØÁª¹æÔò
¹ØÁª²Ù×÷·û () [] -> .
´Ó×óµ½ÓÒ
Ò»Ôª²Ù×÷·û ! – ++ -- + - (type) * & sizeof
´ÓÓÒµ½×ó
³Ë·¨ºÍ³ý·¨ * / %
´Ó×óµ½ÓÒ
¼Ó·¨ºÍ¼õ·¨ + -
´Ó× ......
C/C++Ô¤´¦Àí ISO/ANSI C±ê×¼ÒëÎÄÓë×¢½â
http://blog.csdn.net/huyansoft/archive/2008/05/26/2484297.aspx
<<ISO/ANSI C±ê×¼ÒëÎÄÓë×¢½â C/C++Ô¤´¦Àí²¿·Ö>>
ÄÚÈݼò½é£º±¾ÎĵµÍêÕû·ÒëÁËC±ê×¼(99°æ)ÖÐÔ¤´¦ÀíºÍÏà¹ØÕ½ڵÄÄÚÈÝ£¬²¢ÔÚÐí¶à±ØÒªÖ®´¦¸½¼ÓÁË×¢½âºÍ³ÌÐòʾÀý£¬ÒÔ°ïÖú¶ÁÕßÀí½â±ê×¼ÔÎÄ£¬Í¬Ê±ÖÆ×÷ÁËÏêϸµ ......
Ò»¡¢¶àάÊý×éµØÖ·µÄ±íʾ·½·¨
¡¡¡¡ÉèÓÐÕûÐͶþάÊý×éa[3][4]ÈçÏ£º
¡¡¡¡0 1 2 3
¡¡¡¡4 5 6 7
¡¡¡¡8 9 10 11
¡¡¡¡ÉèÊý×éaµÄÊ×µØַΪ1000£¬¸÷ϱê±äÁ¿µÄÊ×µØÖ·¼°ÆäÖµÈçͼËùʾ¡£
ÔÚÇ°ÃæÔø¾½éÉܹý£¬ CÓïÑÔÔÊÐí°ÑÒ»¸ö¶þάÊý×é·Ö½âΪ¶à¸öһάÊý×éÀ´´¦Àí¡£Òò´ËÊý×éa¿É·Ö½âΪÈý¸öһάÊý×飬¼´a[0]£¬a[1]£¬ ......
ת×Ô¡¾http://tech.ddvip.com/2008-08/121825219252306_3.html¡¿
ÄÚÈÝÕªÒª£ºÒ»Ö±ÒÔÀ´¶¼¾õµÃprintfËƺõÊÇcÓïÑÔ¿âÖй¦ÄÜ×îÇ¿´óµÄº¯ÊýÖ®Ò»£¬²»½öÒòΪËüÄܸñʽ»¯Êä³ö£¬¸üÔÚÓÚËüµÄ²ÎÊý¸öÊýûÓÐÏÞÖÆ£¬Òª¼¸¸ö¾Í¸ø¼¸¸ö£¬À´Õß²»¾Ü¡£printfÕâÖÖ¶Ô²ÎÊý¸öÊýºÍ²ÎÊýÀàÐ͵ÄÇ¿´óÊÊÓ¦ÐÔ£¬ÈÃÈ˲úÉúÁ˶ÔËü½øÐÐ̽Ë÷µÄŨºñÐËȤ¡£
¡¾1. ʹÓÃÇéÐ ......
1¡¢ ¾³£¿´¼ûreturn EXIT_SUCCESS»òreturn EXIT_FAILURE£¬µ«¶¼²»ÖªÕâÁ½¸öÀ´×Ժ䦣¬ÏÖÔÚ²ÅÖªÔÀ´stdlib.h¶¨ÒåÁËEXIT_SUCCESSºÍEXIT_FAILURE·ûºÅ¡£
ÔÚstdlib.hÍ·ÎļþÀ
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
& ......