?
Solved

Timestamps and the number of milliseconds since midnight 1970

Posted on 2007-04-03
4
Medium Priority
?
2,419 Views
Last Modified: 2008-01-09
Hello All,

I have done quite a bit of searching, but I just cannot find any reference to what I'm after.

I'm needing to do something similar to the following:

Dim _CurrentTime = {number of millisecond since midnight 1970} ( the good old timestamp value )
while (true)
Dim _TimeNow = {number of millisecond since midnight 1970}
if ((_TimeNow - 10000) > _CurrentTime)
' break loop
end if
end while

But I cannot find the code required to get the number of milliseconds to test with.

Thanks
Anubis.
0
Comment
Question by:Anubis2005
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18847100
TimeNow= format(now,"hh:mm:ss:ms")
will give you the milliseconds...

Not exactly sure I understand what you're trying to do with it...?
0
 
LVL 1

Author Comment

by:Anubis2005
ID: 18847154
Hello,

Thank you for the prompt response, but that's not what I was after.  Basically I want to get a timestamp in milliseconds before the while begins and then terminate the while if the timestamp reaches 10000 milliseconds later.

For example, in JavaScript I can do the following:
var TimeNow = new Date().getTime()
Which would give me something like: 1175637496502

Thanks.
Anubis.
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 18847502
Why do you need the 1970 thing?

Use the TimeSpan and DateTime classes.  Specifically the DateTime.AddSeconds() function will be helpful.  You can add milliseconds if you wanted to though:
http://msdn2.microsoft.com/en-us/library/system.datetime.addseconds.aspx
http://msdn2.microsoft.com/en-us/library/system.datetime.addmilliseconds.aspx

Something like...

    Private Sub Delay(ByVal DelayInSeconds As Integer)
        Dim ts As TimeSpan
        Dim targetTime As DateTime = DateTime.Now.AddSeconds(DelayInSeconds)
        Do
            ts = targetTime.Subtract(DateTime.Now)
            Application.DoEvents() ' keep app responsive
            System.Threading.Thread.Sleep(50) ' reduce CPU usage
        Loop While ts.TotalSeconds > 0
    End Sub

Example:

    Delay(10) ' hold for ten seconds
0
 
LVL 1

Author Comment

by:Anubis2005
ID: 18847642
The 1970 was just a fimiliar reference as timestamps in other scripting languages such as ASP (classic) or JavaScript use this to generate their millisecond timestamps.

But this is what I was looking for.

Thanks.
Anubis.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question