计算elasped Unix Time in循环

时间:2012-06-29 03:52:34

标签: c# vb.net time webrequest elapsed

我正在进行这些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时间:

  

Public Function UnixNow()As Long

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

    Return CLng(_TimeSpan.TotalSeconds)

End Function

每当我调用UnixTime给我当前时间时,结果总是为0.任何提示?

1 个答案:

答案 0 :(得分: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)