0

我正在执行这些 webrequests 循环,我需要跟踪自第一次请求以来经过的时间(unix 时间)。例如:

    Dim post1 String = "http://www.xxx.com/......" & UnixTimeNow1stCall & "......"
    Dim postReq1 As HttpWebRequest = DirectCast(WebRequest.Create(post1), HttpWebRequest)

    Dim post2 String = "http://www.xxx.com/......" & UnixTimeElasped1stCall& "......"
    Dim postReq2 As HttpWebRequest = DirectCast(WebRequest.Create(post2), HttpWebRequest)


    Dim post3 String = "http://www.xxx.com/......" & UnixTimeElasped1stCall& "......"
    Dim postReq3 As HttpWebRequest = DirectCast(WebRequest.Create(post3), HttpWebRequest)

*LOOP again*

等等。换句话说,我需要在第一次调用中锁定当前的 Unix 时间,并且每当我稍后调用时(以 10 秒为间隔),我需要它来引用第一次调用。

使用它来计算当前的 Unix 时间:

公共函数 UnixNow() 只要

    Dim _TimeSpan As TimeSpan = (DateTime.UtcNow - New DateTime(1970, 1, 1, 0, 0, 0))

    Return CLng(_TimeSpan.TotalSeconds)

End Function

每当我打电话给 UnixTime 时,都会给我当前时间,所以结果总是 0。有什么提示吗?

4

1 回答 1

0

当然 UnixNow 总是会给你当前时间...

存储它并计算差异

Dim unixTimeFirstRequest Long = UnixNow()
Dim post1 String = "http://www.xxx.com/......" & unixTimeFirstRequest & "......"
Dim postReq1 As HttpWebRequest = DirectCast(WebRequest.Create(post1), HttpWebRequest)

Dim post2 String = "http://www.xxx.com/......" & UnixNow() - unixTimeFirstRequest & "......"
Dim postReq2 As HttpWebRequest = DirectCast(WebRequest.Create(post2), HttpWebRequest)


Dim post3 String = "http://www.xxx.com/......" & UnixNow() - unixTimeFirstRequest & "......"
Dim postReq3 As HttpWebRequest = DirectCast(WebRequest.Create(post3), HttpWebRequest)
于 2012-06-29T05:18:02.160 回答