第八课作业

来源:互联网 发布:linux cp 强制覆盖 编辑:程序博客网 时间:2024/06/05 18:20

获取系统时间。本想利用clrscr()函数刷新DOS窗口的,结果c-free中貌似不能用,所以只好用Dos命令“cls”刷新屏幕。

C代码:

Code:
  1. #include <stdio.h>  
  2. #include <time.h>  
  3. #include <conio.h>  
  4. #include <windows.h>  
  5.   
  6. #ifndef _TM_DEFINED  
  7. /* 
  8.  * A structure for storing all kinds of useful information about the 
  9.  * current (or another) time. 
  10.  */  
  11. struct tm  
  12. {  
  13.     int tm_sec;     /* Seconds: 0-59 (K&R says 0-61?) */  
  14.     int tm_min;     /* Minutes: 0-59 */  
  15.     int tm_hour;    /* Hours since midnight: 0-23 */  
  16.     int tm_mday;    /* Day of the month: 1-31 */  
  17.     int tm_mon;     /* Months *since* january: 0-11 */  
  18.     int tm_year;    /* Years since 1900 */  
  19.     int tm_wday;    /* Days since Sunday (0-6) */  
  20.     int tm_yday;    /* Days since Jan. 1: 0-365 */  
  21.     int tm_isdst;   /* +1 Daylight Savings Time, 0 No DST, 
  22.                  * -1 don't know */  
  23. };  
  24. #define _TM_DEFINED  
  25. #endif  
  26.   
  27. int main(int argc, char *argv[])  
  28. {  
  29.     while(!feof(stdin)) 
  30.     {  
  31.         time_t sconfieldTimer;  
  32.         struct tm*tt;  
  33.         time(&sconfieldTimer);  
  34.         tt=localtime(&sconfieldTimer);   
  35.         printf("%d-%02d-%02d %02d:%02d:%02d/n",  
  36.             (*tt).tm_year+1900,tt->tm_mon+1,tt->tm_mday,  
  37.             tt->tm_hour,tt->tm_min,tt->tm_sec);  
  38.         Sleep(1000);  
  39.         system("cls");    
  40.     }  
  41.     return 0;  
  42. }  

C#代码:

Code:
  1. /* 
  2.  * Created by SharpDevelop. 
  3.  * User: Sconfield 
  4.  * Date: 2009/9/3 
  5.  * Time: 11:50 
  6.  *  
  7.  * To change this template use Tools | Options | Coding | Edit Standard Headers. 
  8.  */  
  9.   
  10. using System;  
  11. namespace SconfieldTimer  
  12. {  
  13.     class MyTimer  
  14.     {  
  15.         static void Main()  
  16.         {  
  17.             Console.WriteLine(DateTime.Now);  
  18.         }  
  19.     }  
  20. }  

 

原创粉丝点击