| | |
US Naval Observatory Master Clock Time (C#)
Please support our C# advertiser: Intel Parallel Studio Home
A short C# code snippet to get the US Naval Observatory Master Clock Time from:
http://tycho.usno.navy.mil/cgi-bin/timer.pl
The snippet displays the raw HTML code with the time infomation and then extracts one specific US time zone.
http://tycho.usno.navy.mil/cgi-bin/timer.pl
The snippet displays the raw HTML code with the time infomation and then extracts one specific US time zone.
// this C# program gets the US Naval Observatory Master Clock Time // SnippetCompiler.exe was used to write, compile (uses .NET V2 csc.exe) // and run this code, a handy little C# utility free from: // http://www.sliver.com/dotnet/SnippetCompiler/ using System; using System.Net; // HttpWebRequest using System.IO; // StringReader using System.Text; // StringBuilder class NavyTime { static public void Main(string[] args) { string navyURL = "http://tycho.usno.navy.mil/cgi-bin/timer.pl"; string htmlTimeStr = GetHTML(navyURL); string strMyDateTime = null; StringReader strReader = new StringReader(htmlTimeStr); string line; // extract the Pacific Time Zone information while ((line = strReader.ReadLine()) != null) { // use the Pacific Time Zone line int pos = line.LastIndexOf("PDT"); if (pos != -1) { //start from pos 4 because of the <BR> tag strMyDateTime = line.Substring(4, pos - 4); break; } } Console.WriteLine("Raw HTML_code time information:"); Console.WriteLine(htmlTimeStr); // sorry, the US Navy does not supply the year Console.WriteLine("Pacific Time Zone time:"); Console.WriteLine(strMyDateTime); Console.Write("\nPress Enter to exit ..."); Console.Read(); // console display, wait for key } // extract the HTML code with time information static string GetHTML(string url) { StringBuilder sb1 = new StringBuilder(); byte[] buf1 = new byte[4096]; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream resStream = response.GetResponseStream(); string tempString = null; int count = 0; while (0 < (count = resStream.Read(buf1, 0, buf1.Length))) { tempString = Encoding.ASCII.GetString(buf1, 0, count); sb1.Append(tempString); } return sb1.ToString(); } }
0
•
•
•
•
I use the US Naval Observatory Master Clock to set my watch and clocks at home because it is reliable.
http://www.1-satellite-tv-facts.com
http://www.1-satellite-tv-facts.com/Direct-TV.html
http://www.1-satellite-tv-facts.com/Dish-Network.html
http://www.1-satellite-tv-facts.com/...ite-Radio.html
http://www.1-satellite-tv-facts.com/...t-Service.html
http://www.1-satellite-tv-facts.com/Satellite-DSL.html
http://www.1-satellite-tv-facts.com/...-Internet.html
http://www.1-satellite-tv-facts.com/VoIP.html
http://www.1-satellite-tv-facts.com/Phone-Systems.html
http://www.1-satellite-tv-facts.com/...-Programs.html
http://www.1-satellite-tv-facts.com
http://www.1-satellite-tv-facts.com/Direct-TV.html
http://www.1-satellite-tv-facts.com/Dish-Network.html
http://www.1-satellite-tv-facts.com/...ite-Radio.html
http://www.1-satellite-tv-facts.com/...t-Service.html
http://www.1-satellite-tv-facts.com/Satellite-DSL.html
http://www.1-satellite-tv-facts.com/...-Internet.html
http://www.1-satellite-tv-facts.com/VoIP.html
http://www.1-satellite-tv-facts.com/Phone-Systems.html
http://www.1-satellite-tv-facts.com/...-Programs.html
Similar Threads
- Real time clock (C++)
- Code Snippet: Colorful clock of Time (Shell Scripting)
- time clock programs?? (Windows NT / 2000 / XP)
- clock not keeping time (Motherboards, CPUs and RAM)
- XP Clock only 24 hour time? (Windows NT / 2000 / XP)
| Thread Tools | Search this Thread |
.net access algorithm api array asp.net barchart bitmap box broadcast c# check checkbox client combobox control conversion csharp custom database databaseconnection datagrid datagridview dataset datetime dbconnection degrees design development draganddrop drawing encryption enum event eventhandlers excel file firefox form format forms function gdi+ httpwebrequest image index input install java label libraries list listbox loop mandelbrot marshalbyrefobject math mouseclick movingimage mysql mysql.data.client operator path photoshop php picturebox pixelinversion platform post programming radians regex remoting resourcefile richtextbox server sleep socket sql statistics stream string study system.servicemodel table tcpclientchannel text textbox thread time timer update usercontrol validation visualstudio webbrowser windows winforms wpf xml



