我正在计算从aspx第1页到第2页需要多少秒。这次没有反映真正的时钟..错误在哪里?
第1页我有:
Session("sessioncreated") = Now.Ticks
第2页我有:
Dim diff As Long = 0
If Not Session("sessioncreated") Is Nothing Then
diff = Now.Ticks - Session("sessioncreated")
End If
Dim timediff As Integer = TimeSpan.FromTicks(diff).Seconds
答案 0 :(得分:3)
了解您所看到的问题会有所帮助...... 无论如何,我认为你应该改变:
Dim timediff As Integer = TimeSpan.FromTicks(diff).Seconds
到
Dim timediff As Integer = TimeSpan.FromTicks(diff).TotalSeconds
答案 1 :(得分:1)
使用: -
Session("sessioncreated") = Now
Dim diff as TimeSpan
If Not Session("sessioncreated") Is Nothing Then
diff = Now - DirectCast(Session("sessioncreated"), DateTime)
End If
Dim timediff As Integer = diff.TotalSeconds
答案 2 :(得分:0)
保持简单
Dim stpw As New Stopwatch 'declare in the class
'on page 1
stpw.Reset()
stpw.Start()
'on page 2
stpw.Stop()
'stpw.Elapsed.TotalSeconds 'will contain seconds between the two