| | |
US Naval Observatory Master Clock Time (C#)
Please support our C# advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
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 animation array bitmap box c# check checkbox client combobox control conversion csharp customactiondata database datagrid datagridview dataset datastructure date/time datetime datetimepicker degrees directrobot dll draganddrop drawing encryption enum excel file filename files form format formbox forms function gdi+ gis gtk hash image input install java label list mandelbrot math mouseclick mp3 mysql native operator outlook2003 packaging path photoshop picturebox pixelinversion pixelminversion post print process programming radians regex remoting richtextbox safari server sleep snooze socket sql statistics string table tables tcp text textbox thread time timer update usercontrol usercontrols validation visualstudio webbrowser webcam wfa wia winforms wpf xml



