?
Solved

Timestamps and the number of milliseconds since midnight 1970

Posted on 2007-04-03
4
Medium Priority
?
2,478 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
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

850 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