Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QM DATE conversion
#1
I want to convert the following sources to QM.

But, "QM? ----" I don't know the command for the three lines below the comment.

Could you tell me how to change it?

Function Function10
Code:
Copy      Help
str Headers =
;Host: nist.time.gov
;Connection: keep-alive
;Cache-Control: max-age=0
;Upgrade-Insecure-Requests: 1
;User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
;Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
;Accept-Encoding: deflate, sdch

str ResponeHeader HTML
Http HttpWebRequest.Connect("http://nist.time.gov" 0 0 0)
,,HttpWebRequest.Get2("/actualtime.cgi?lzbc=siqm9b" HTML 0 INTERNET_FLAG_NO_COOKIES|INTERNET_FLAG_NO_CACHE_WRITE ResponeHeader Headers)

if(!findrx(HTML "(?<=\btime='')[^'''']*" 0 RX_DOTALL _s)>=0)
,out _s

;QM ?----
;double milliseconds = Convert.ToInt64(time) / 1000.0;
;DateTime d.FromStr(1970, 1, 1)AddMilliseconds(milliseconds).ToLocalTime();
;ret dateTime.ToString()
;----------------


;out
;str endTime=sub.NistTime
;out endTime


#sub NistTime

;Credit goes to Nemo from Stack Overflow:
;http://stackoverflow.com/questions/6435099/how-to-get-datetime-from-the-internet/6435207#6435207

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 = "";
,,request.UserAgent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)";
,,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();
,}    
}
#2
Macro Macro2871
Code:
Copy      Help
_s="1497246027298501"
DateTime t.FromParts(1970 1 1)
t.AddParts(0 0 0 0 0 val(_s 2))
t.UtcToLocal
out t.ToStr
#3
I solved the problem thanks to this

Function Test_NistTime
Code:
Copy      Help
function~
str Headers =
;Host: nist.time.gov
;Connection: keep-alive
;Cache-Control: max-age=0
;Upgrade-Insecure-Requests: 1
;User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
;Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
;Accept-Encoding: deflate, sdch

str ResponeHeader HTML
Http HttpWebRequest.Connect("http://nist.time.gov" 0 0 0)
,,HttpWebRequest.Get2("/actualtime.cgi?lzbc=siqm9b" HTML 0 INTERNET_FLAG_NO_COOKIES|INTERNET_FLAG_NO_CACHE_WRITE ResponeHeader Headers)


if(!findrx(HTML "(?<=\btime='')[^'''']*" 0 RX_DOTALL _s)>=0)
,DateTime t
,t.FromParts(1970 1 1)
,t.AddParts(0 0 0 0 0 val(_s 2))
,t.UtcToLocal()
ret t.ToStr(4)

Function Function11
Code:
Copy      Help
str UTC=Test_NistTime
out UTC
#4
no, I would probably use this

Macro Macro2872
Code:
Copy      Help
if !HttpWebRequest.Get2("/actualtime.cgi?lzbc=siqm9b" HTML 0 INTERNET_FLAG_NO_COOKIES|INTERNET_FLAG_NO_CACHE_WRITE ResponeHeader Headers)
,end F"failed to connect. {HttpWebRequest.lasterror}"
#5
Thank you for your reply.
I am sorry to ask you for help and I tried to solve it by myself
But thanks for helping me like this. Big Grin
#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?
#7
nist.time.gov is very slow, sometimes even does not work, but in most times works.
Another script - function IntSetClock in Archive.qml (the first topic in the Resources subforum). It's fast, but does not get year and milliseconds.
#8
Any idea where I can get the function? And does the function get the time from online?
#9
That version sets computer time. This version just returns time.

Function GetInternetTime_tycho_usno_navy_mil
Code:
Copy      Help
;/
function! DateTime&t

;Gets current UTC time from http://tycho.usno.navy.mil/timer.html.
;Returns 1 if successful. Returns 0 if fails to connect. Error if web page removed or modified.

;REMARKS
;The web page does not contain year and milliseconds. For year this function uses the computer's clock.

;EXAMPLE
;DateTime t
;if(!GetInternetTime_tycho_usno_navy_mil(t)) out "failed"; ret
;t.UtcToLocal
;out t.ToStr(4)


if(!IntPing("http://tycho.usno.navy.mil")) ret
;download file
Http h; str s
if(!h.GetUrl("http://tycho.usno.navy.mil/timer.html" &s)) ret
;get time string
ARRAY(str) a
if(findrx(s "(\w{3})\. (\d\d), (\d\d):(\d\d):(\d\d)" 0 2 a)<0) end "changed web page"
;get current time (year is missing in web file)
SYSTEMTIME st; GetSystemTime &st
;fill structure
lpstr m="JanFebMarAprMayJunJulAugSepOctNovDec"
int i=find(m a[1]); if(i<0) end "changed web page"
st.wMonth=i/3+1
st.wDay=val(a[2])
st.wHour=val(a[3])
st.wMinute=val(a[4])
st.wSecond=val(a[5])
st.wMilliseconds=999

t.FromSYSTEMTIME(st)
ret 1
#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
#11
Alright. Fixed it myself.

Macro Test1
Code:
Copy      Help
DateTime t x
int a
if(!GetInternetTime_tycho_usno_navy_mil(t)) mes "Date Time Error!"; end
t.UtcToLocal
x.FromComputerTime

long vDiff=t-x
vDiff/10000000
out vDiff


Forum Jump:


Users browsing this thread: 9 Guest(s)