dz̸ Èý²ã½á¹¹ Ô­Àí£¬Ç³Ì¸ÍøÂçʱ¼äУÕýÔ­Àí¼°Êµ¼ùÔËÓÃ

dz̸ÍøÂçʱ¼äУÕýÔ­Àí¼°Êµ¼ùÔËÓà - ²ËÄñѧԺ - µçÄԽ̳ÌÍø

dz̸ÍøÂçʱ¼äУÕýÔ­Àí¼°Êµ¼ùÔËÓÃ

ÈÕÆÚ£º2007-03-28   ¼ö£º
Ëæ×ÅÐÅÏ¢¼¼ÊõµÄ·¢Õ¹£¬Ê±¼ä¶ÔÈËÃÇÔ½À´Ô½ÖØÒªÁË£¬ÕýËùν¡°Ð§ÂʾÍÊǽðÇ®£¬Ê±¼ä¾ÍÊÇÉúÃü¡±¡£²»¹ý£¬±¾ÎIJ¢²»´òËã½éÉÜÈçºÎ°²ÅÅʱ¼ä£¬¶øÊÇÒª½éÉܺÏÀíÀûÓÃʱ¼äµÄ»ù´¡¡ª¡ªÊ±¼äУÕý¡£ÓùýÒ»¶Îʱ¼äµçÄÔµÄÈËÓ¦¸ÃÖªµÀ£¬µçÄÔÉϵÄʱÖÓÍùÍùÊDz»×¼È·µÄ£¬¶øÇÒ¾­³£Êǵ÷ÕûÒԺ󲻾þÍÂÒÁË¡£ÕâÖÖÎó²îÊÇÓÉCMOSÄÚ²¿µÄ¼Æʱµç·ÒýÆðµÄ¡£¼ÈÈ»ÎÒÃÇÎÞ·¨´ÓÓ²¼þÉ϶žøÕâ¸öÎÊÌ⣬ÎÒÃǾÍÒªÏë°ì·¨´ÓÈí¼þÉÏÃÖ²¹¡£
¡¡¡¡Ê×ÏȽéÉÜÒ»ÏÂÍøÂç¶Ô±íµÄÔ­Àí¡£ÍøÂçÉÏ´æÔںܶà½Ð×ö¡°ÊÚʱ·þÎñÆ÷¡±µÄÖ÷»ú£¬ËüÃǸºÔðÌṩ¾«È·µÄʱ¼ä£¬Ò»°ãÊÇÓÉÔ­×ÓÖÓ²úÉúµÄ¡£Òò´Ë£¬ÎÒÃÇÖ»Òª×öÒ»¸öС³ÌÐòÀ´ÓëÊÚʱ·þÎñÆ÷ͨÐŲ¢°´ÕÕÆä·µ»ØµÄ׼ȷʱ¼äÀ´µ÷Õû±¾»úʱ¼ä¾Í¿ÉÒÔÁË¡£
¡¡¡¡ÆäÖÐRFC×é֯ΪÍøÂçʱ¼äЭÒé¹æ¶¨Á˼¸¸ö²»Í¬°æ±¾£º
¡¡¡¡DayTimeЭÒ飺ÕâÊÇÒÔASCII×Ö·û´«µÝʱ¼äÐÅÏ¢µÄÒ»ÖÖЭÒé¡£²Î¼ûRFC0867¡£
¡¡¡¡TimeЭÒ飺ÕâÊÇÒÔ32λÕûÊý´«µÝʱ¼äÐÅÏ¢µÄÒ»ÖÖЭÒé¡£²Î¼ûRFC0868¡£
¡¡¡¡Simple Network TimeЭÒ飺ÕâÊÇÒ»ÖÖ¸ü¼Ó¾«È·µÄ´«µÝʱ¼äÐÅÏ¢µÄЭÒé¡£²Î¼ûRFC1769¡£
¡¡¡¡Äã¿ÉÒÔÔÚhttp://rfc.linuxforum.net/ÕÒµ½Ïà¹ØRFCЭÒé¡£
¡¡¡¡Õ⼸¸öЭÒé¸÷ÓÐÓŵ㣬DayTimeЭÒé×î¼òµ¥£¬×îÖ±¹Û£¬µ«¹æ·¶²»Í³Ò»£¬Ö»ÊʺÏÈËÄÔÔĶÁ£»TimeЭÒéÒ²·Ç³£¼òµ¥£¬µ«¸üÊʺÏÓóÌÐòÀ´Í³Ò»´¦Àí£»Simple Network TimeЭÒé±È½Ï¸´ÔÓ£¬µ«¾«¶È·Ç³£¸ß¡£ÏÂÃæÎÒ½«Ö÷Òª½éÉÜÒ»ÏÂTimeЭÒéµÄʵÏÖÓëÓ¦Óá£
¡¡¡¡TimeЭÒéÖÐÓëÊÚʱ·þÎñÆ÷µÄͨÐÅÊǷdz£¼òµ¥µÄ£º
screen.width-300)this.width=screen.width-300" border=0>

ÆäÖС°Á¬½Ó¡±ÊÇÖ¸Á¬½Óµ½·þÎñÆ÷µÄ37¶Ë¿Ú£¨TCP»òUDP·½Ê½¾ù¿É£¬ÕâÀïÎÒÃǽ«Ñ¡ÓÃTCP·½Ê½£©¡£ÆäÖС°Ê±¼äÐÅÏ¢¡±ÊÇÒ»¸ö4×Ö½Ú³¤µÄÕûÊý£¬¶¨ÒåÈçÏ£ºËü±íʾ×Ô´ÓGMT 0ʱÇø1900Äê1ÔÂ1ÈÕÎçÒ¹00:00¿ªÊ¼µ½ÏÖÔÚËù¾­¹ýµÄÃëÊý¡£²»¹ýÕâ¸öʱ¼äÊÇÒÔ±¾³õ×ÓÎçÏß´¦µÄʱ¼äΪ±ê×¼µÄ¡£ÎªÁË»ñµÃ±¾µØʱ¼ä£¬ÎÒÃÇ»¹Òª°´Ê±Çø½øÐÐÐÞÕý¡£ÀýÈ磬Öйú´¦ÓÚ¶«°ËÇø£¬ËùÒÔÒª°Ñ»ñµÃµÄʱ¼ä¼ÓÉÏ8Сʱ¡£µ±Ê±¼äÐÅÏ¢·µ»Øºó£¬·þÎñÆ÷½«Ö÷¶¯¹Ø±ÕÕâ¸öÁ¬½Ó¡£
¡¡¡¡ÏÂÃæÎÒÃǾÍÓÃC#ʵÏÖÕâ¸ö³ÌÐòÁË¡£Ð½¨Ò»¸ö½ÐTimeSyncµÄC# WindowsÓ¦ÓóÌÐò¹¤³Ì¡£ÆäÖÐForm1¸ÄÃûΪfrmMain¡£ÔÚfrmMain´úÂëÇ°²åÈ룺
using System.Threading; //ÐèҪʹÓöàÏß³Ì
using System.Net; //ÐèҪʹÓÃÍøÂç
using System.Net.Sockets; //ÐèҪʹÓÃÍøÂç
//ÐèÒªµ÷ÓÃAPIÀ´ÉèÖÃϵͳʱ¼ä¡£
//±ÊÕßÔø¾­Ïëͨ¹ýC#µÄÀà¿âÀ´ÐÞ¸Äϵͳʱ¼ä£¬µ«Ò»Ö±Ã»ÓÐʵÏÖ¡£
//Ï£ÍûÊìϤÕâ·½ÃæµÄÅóÓÑÖ¸µãһϡ£
using System.Runtime.InteropServices;
class Win32API
{
[DllImport("kernel32.dll")]
public static extern int SetLocalTime (ref SystemTime lpSystemTime);
}
public strUCt SystemTime
{
public short wYear;
public short wMonth;
public short wDayOfWeek;
public short wDay;
public short wHour;
public short wMinute;
public short wSecond;
public short wMilliseconds;
}
¡¡¡¡Ö÷´úÂ룺
public class frmMain : System.Windows.Forms.Form
{
////Ê¡ÂÔ×Ô¶¯Éú³ÉµÄ´úÂë
////¡­¡­¡­¡­¡­
Thread thrTimeSync;
private void TimeSyncProc()
{
while(true)
{
¡¡TcpClient c = new TcpClient();
¡¡c.Connect("www.time.ac.cn", 37);¡¡ //Á¬½Óµ½¹úÄÚÊÚʱ·þÎñÆ÷
¡¡NetworkStream s;
¡¡s = c.GetStream();¡¡¡¡¡¡¡¡¡¡//¶ÁÈ¡Êý¾ÝÁ÷
¡¡c.Close();
¡¡byte []buf = new byte[4];
¡¡s.Read(buf,0,4);¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ //°ÑÊý¾Ý´æµ½Êý×éÖÐ
¡¡uint lTime;
¡¡//°Ñ·þÎñÆ÷·µ»ØÊý¾Ýת»»³É1900/1/1 UTC µ½ÏÖÔÚËù¾­¹ýµÄÃëÊý
¡¡lTime = ((uint)buf[0]

£¨³ö´¦£ºhttp://www.sheup.com£©




±êÇ©£º