Solved

Timestamps and the number of milliseconds since midnight 1970

Posted on 2007-04-03
4
2,372 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
  • 2
4 Comments
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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
Comment Utility
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 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now