當前位置:首頁 » 操作系統 » 毫秒源碼

毫秒源碼

發布時間: 2023-08-05 17:07:46

㈠ 求C++獲取系統時間源代碼,精確到毫秒

#include <iostream>
#include <windows.h>

using namespace std;

void main()
{

SYSTEMTIME time;//時間結構聲明,這個結構是系統的,
GetSystemTime( &time );//調用獲取系統時間api.
//GetLocalTime();這個函數是獲取本地時間api
char* t_y;
char* t_m;
char* t_h;
char* t_Min;
char* t_s;
char* t_Mi;
char* t_d;
char* t_w;

SYSTEMTIME time;//時間結構聲明,這個結構是系統的,
GetSystemTime( &time );//調用獲取系統時間api.
sprintf(t_y, "%d", time.wYear);//將年份格式輸出到t_y變數中
sprintf(t_m, "%d", time.wMonth);
sprintf(t_w, "%d", time.wDayOfWeek);
sprintf(t_d, "%d", time.wDay);
sprintf(t_h, "%d", time.wHour);
sprintf(t_Min, "%d", time.wMinute);
sprintf(t_s, "%d", time.wSecond);
sprintf(t_Mi, "%d", time.wMilliseconds);
printf("%s,%s,%s,%s,%s,%s,%s,%s",
time.wYear,
time.wMonth,
time.wDayOfWeek,
time.wDay,
time.wHour,
time.wMinute,
time.wSecond,
time.wMilliseconds);

}
/***
SYSTEM 結構成員如下:
SYSTEMTIME STRUCT
{
WORD wYear ; 年
WORD wMonth ;月
WORD wDayOfWeek ;星期,0=星期日,1=星期一...
WORD wDay ;日
WORD wHour ;時
WORD wMinute ;分
WORD wSecond ;秒
WORD wMilliseconds ;毫秒
}SYSTEMTIME ENDS
//***/

㈡ 用flash as3.0製作一個10分鍾倒計時(精確到毫秒)!求源代碼~~

這種樣子的,行嗎?

㈢ 求幾個比較有趣,簡單的C語言源代碼 小白自己敲著練一下手感

最簡單的模擬計時器:

#include<stdio.h>

#include<conio.h>

#include<windows.h>

int m=0,s=0,ms=0; //m是分 s是秒 ms是毫秒

//以下是5個自編函數

void csh( ); //初始化界面

void yinc(int x,int y); //隱藏游標的函數(y值設為0就會隱藏)

void jishi( ); //計時器運行(每100毫秒變化一次)

void Color (short x, short y); //設定顏色的函數(y設為0就是黑底)

void gtxy (int x, int y); //控制游標位置的函數

int main( ) //主函數

{ csh( );

getch( );

while(1)

{ jishi( );

Sleep(100); //間隔100毫秒

if( kbhit( ) )break; //有鍵按下就退出循環

}

return 0;

}

void csh( ) //初始化界面

{Color(14,0); //設定淡黃字配黑底

printf(「 計時器」);

Color(10,0); //設定淡綠字配黑底

printf(" ┌───────────┐");

printf(" │ │");

printf(" └───────────┘");

gtxy(10,4); //游標到屏幕第10列4行處輸出

Color(7,0); //恢復白字黑底

printf(" 00:00:00 ");

yinc(1,0 ); //隱藏游標(yinc代表隱藏)

return;

}

void jishi( ) //計時器運行

{ms+=1;

if(ms==10){s+=1;ms=0;}

if(s==60){m+=1;s=0;}

gtxy(10,4);

Color(9,0); //設定淡藍字配黑底

if(m>9) printf(" %d:",m);

else printf(" 0%d:",m);

Color(14,0); //設定淡黃字配黑底

if(s>9) printf("%d:",s);

else printf("0%d:",s);

Color(12,0); //設定淡紅字配黑底

printf("0%d",ms);

}

void gtxy (int x, int y) //控制游標位置的函數

{ COORD pos;

pos.X = x;

pos.Y = y;

SetConsoleCursorPosition ( GetStdHandle (STD_OUTPUT_HANDLE), pos );

}

void Color (short ForeColor= 7, short BackGroundColor= 0) //設定顏色的函數

{ HANDLE handle = GetStdHandle ( STD_OUTPUT_HANDLE );

SetConsoleTextAttribute ( handle, ForeColor + BackGroundColor * 0x10 );

}

void yinc(int x,int y) //隱藏游標的設置(gb代表游標)

{ CONSOLE_CURSOR_INFO gb={x,y}; //x為1-100,y為0就隱藏游標

SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &gb);

}

熱點內容
pythonforaix 發布:2025-03-12 23:32:02 瀏覽:309
linux命令清理 發布:2025-03-12 23:17:15 瀏覽:5
手機文件夾趣味名字6個 發布:2025-03-12 23:17:12 瀏覽:497
解釋程序和編譯程序 發布:2025-03-12 23:15:47 瀏覽:571
色豬視頻為什麼沒有伺服器 發布:2025-03-12 23:15:46 瀏覽:123
如龍極2低配置怎麼調 發布:2025-03-12 23:14:06 瀏覽:374
androidopencamera 發布:2025-03-12 23:05:27 瀏覽:816
雲購網源碼 發布:2025-03-12 23:00:29 瀏覽:618
騰訊雲伺服器上的電腦打不開 發布:2025-03-12 22:55:29 瀏覽:942
安卓系統怎麼退出遊戲 發布:2025-03-12 22:42:37 瀏覽:665