Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QM DATE conversion
#6
Code:
Copy      Help
function~
CsScript x.AddCode("")
ret x.Call("Test.iNetTime")

#ret
using System;
using System.IO;
using System.Net;
using System.Net.Cache;
using System.Text.RegularExpressions;

public class Test
{
    public static string iNetTime()
    {
        DateTime dateTime = DateTime.MinValue;

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://nist.time.gov/actualtime.cgi?lzbc=siqm9b");
        request.Method = "GET";
        request.Accept = "text/html, application/xhtml+xml, */*";
        request.UserAgent = "Mozilla/5.0 (Macintosh; U; Mac OS X 10_6_1; en-US) AppleWebKit/530.5 (KHTML, like Gecko) Chrome/ Safari/530.5";
        request.ContentType = "application/x-www-form-urlencoded";
        request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); //No caching
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        if (response.StatusCode == HttpStatusCode.OK)
        {
            StreamReader stream = new StreamReader(response.GetResponseStream());
            string html = stream.ReadToEnd();
            string time = Regex.Match(html, @"(?<=\btime="")[^""]*").Value;
            double milliseconds = Convert.ToInt64(time) / 1000.0;
            dateTime = new DateTime(1970, 1, 1).AddMilliseconds(milliseconds).ToLocalTime();
        }
        return dateTime.ToString();
    }    
}

This is what I have. Stolen this from someone else in the past. Apparently the url (http://nist.time.gov/actualtime.cgi?lzbc=siqm9b) is down. Any idea on how to solve this or any other alternative website?


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)