Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QM DATE conversion
#10
This is what I have currently.

Function NistTime
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();
,}    
}

Function DateChecker
Code:
Copy      Help
function
str vDiff
str endTime=NistTime
DateTime x
x.FromComputerTime
str startTime=x.ToStr(4)
sub.TimeDiff startTime endTime

#sub TimeDiff
function $startTime $endTime

DateTime vStart vEnd
vStart.FromStr(startTime)
vEnd.FromStr(endTime)
long vDiff=vEnd-vStart
vDiff/10000000
out vDiff

Any idea how can I do the same thing without changing much?

*Note* I don't know anything about C++ XD


Messages In This Thread

Forum Jump:


Users browsing this thread: 4 Guest(s)