获取系统时间。本想利用clrscr()函数刷新DOS窗口的,结果c-free中貌似不能用,所以只好用Dos命令“cls”刷新屏幕。
C代码:
- #include <stdio.h>
- #include <time.h>
- #include <conio.h>
- #include <windows.h>
- #ifndef _TM_DEFINED
- /*
- * A structure for storing all kinds of useful information about the
- * current (or another) time.
- */
- struct tm
- {
- int tm_sec; /* Seconds: 0-59 (K&R says 0-61?) */
- int tm_min; /* Minutes: 0-59 */
- int tm_hour; /* Hours since midnight: 0-23 */
- int tm_mday; /* Day of the month: 1-31 */
- int tm_mon; /* Months *since* january: 0-11 */
- int tm_year; /* Years since 1900 */
- int tm_wday; /* Days since Sunday (0-6) */
- int tm_yday; /* Days since Jan. 1: 0-365 */
- int tm_isdst; /* +1 Daylight Savings Time, 0 No DST,
- * -1 don't know */
- };
- #define _TM_DEFINED
- #endif
- int main(int argc, char *argv[])
- {
- while(!feof(stdin))
- {
- time_t sconfieldTimer;
- struct tm*tt;
- time(&sconfieldTimer);
- tt=localtime(&sconfieldTimer);
- printf("%d-%02d-%02d %02d:%02d:%02d/n",
- (*tt).tm_year+1900,tt->tm_mon+1,tt->tm_mday,
- tt->tm_hour,tt->tm_min,tt->tm_sec);
- Sleep(1000);
- system("cls");
- }
- return 0;
- }
C#代码:
- /*
- * Created by SharpDevelop.
- * User: Sconfield
- * Date: 2009/9/3
- * Time: 11:50
- *
- * To change this template use Tools | Options | Coding | Edit Standard Headers.
- */
- using System;
- namespace SconfieldTimer
- {
- class MyTimer
- {
- static void Main()
- {
- Console.WriteLine(DateTime.Now);
- }
- }
- }