Click here to Skip to main content
6,634,665 members and growing! (17,895 online)
Email Password   helpLost your password?
General Programming » Date and Time » Tools     Intermediate

Time Client (RFC868)

By Orkun GEDiK

Learn how to synchronize your date and time
VC6, VC7Win2K, WinXP, MFC, Dev
Posted:23 Feb 2002
Updated:6 Apr 2002
Views:78,847
Bookmarked:20 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
17 votes for this article.
Popularity: 4.63 Rating: 3.76 out of 5
1 vote, 25.0%
1

2

3
1 vote, 25.0%
4
2 votes, 50.0%
5

Introduction

This article describes a time client which uses RFC 868 protocol. The program uses TCP port 37 for connection with a time server. This is a MFC based console application.

The following block calculates current date and time.

lnTime = (long)((sBuffer - (unsigned long)(DATE_1970)));
Time_Int64 = Int32x32To64(lnTime, 10000000) + 116444736000000000;
FileTime.dwLowDateTime = (DWORD)Time_Int64;
FileTime.dwHighDateTime = Time_Int64 >> 32;
FileTimeToLocalFileTime(&FileTime, &LocalFileTime);
FileTimeToSystemTime(&LocalFileTime, &SystemTime);
SetLocalTime( &SystemTime );

The time is calculated and converted to 64-bit in the first and second lines and then converted to local time zone before being converted to a SYSTEMTIME structure. Last of all the system time is set.

The following is the procedure for communicating with the time server. (These notes are copied from http://www.faqs.org/rfcs/rfc868.html )

  1. S: Listen on port 37 (45 octal).
  2. U: Connect to port 37.
  3. S: Send the time as a 32 bit binary number.
  4. U: Receive the time.
  5. U: Close the connection.
  6. S: Close the connection.

The server listens for a connection on port 37. When the connection is established, the server returns a 32-bit time value and closes the connection. If the server is unable to determine the time at its site, it should either refuse the connection or close it without sending anything. The most important thing is, the time is the number of seconds since 00:00 (midnight) 1 January 1900 GMT, such that the time 1 is 12:00:01 am on 1 January 1900 GMT; this base will serve until the year 2036.

For example:

  • 2,208,988,800 corresponds to 00:00 1 Jan 1970 GMT
  • 2,398,291,200 corresponds to 00:00 1 Jan 1976 GMT
  • 2,524,521,600 corresponds to 00:00 1 Jan 1980 GMT
  • 2,629,584,000 corresponds to 00:00 1 May 1983 GMT
  • and -1,297,728,000 corresponds to 00:00 17 Nov 1858 GMT.

You can use the time.ien.it time service for testing (settime time.ien.it).I hope you have enjoyed with my time client. You can send any bug or comments via e-mail.

My e-mail : Orkun GEDiK

License

About the Author

Orkun GEDiK


Member
I'm working at Yasar Holding IT department as senior SAP R/3 BASIS and Development Consultant and system integrator. I have experience on C/C++ for 6 years. Implementing and inviting new technologies is most biggest part of my life. Object oriented paradigm is a philosophy of my vision.
Occupation: Software Developer (Senior)
Company: ASTRON
Location: Turkey Turkey

Other popular Date and Time articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 18 of 18 (Total in Forum: 18) (Refresh)FirstPrevNext
GeneralDialog + separate thread Pinmemberbruno voisin7:17 20 Sep '03  
GeneralNeed More Help Pinmembermjdeibert5:04 14 May '03  
GeneralRe: Need More Help PinmemberAhmet Orkun GEDiK2:43 21 May '03  
GeneralCan't get the files to compile Pinmemberniverson11:11 16 Aug '02  
GeneralRe: Can't get the files to compile PinsussOGED12:20 16 Aug '02  
GeneralRe: Can't get the files to compile Pinmemberniverson13:16 16 Aug '02  
GeneralSlight Bug PinmemberJohn Burton3:19 8 Apr '02  
GeneralRe: Slight Bug PinmemberAhmet Orkun GEDiK10:10 8 Apr '02  
GeneralSomething wrong PinmemberDavide Zaccanti6:29 7 Apr '02  
GeneralRe: Something wrong PinmemberAhmet Orkun GEDiK10:46 7 Apr '02  
GeneralList of timeservers PinmemberAnonymous1:02 2 Mar '02  
GeneralRe: List of timeservers (correction) PinmemberDavidCrow17:14 6 Apr '04  
GeneralSimple but useful example PinmemberAnonymous17:07 26 Feb '02  
GeneralRe: Simple but useful example PinmemberAhmet Orkun GEDiK2:04 27 Feb '02  
GeneralCut/Paste PinmemberTodd Jeffreys11:14 24 Feb '02  
GeneralRe: Cut/Paste PinmemberAhmet Orkun GEDiK11:32 25 Feb '02  
GeneralRe: Cut/Paste PinmemberPierre Couderc23:43 7 Apr '02  
GeneralRe: Cut/Paste PinmemberAhmet Orkun GEDiK10:11 8 Apr '02  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 6 Apr 2002
Editor: James Spibey
Copyright 2002 by Orkun GEDiK
Everything else Copyright © CodeProject, 1999-2009
Web21 | Advertise on the Code Project