Timestamps and the number of milliseconds since midnight 1970

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.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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...?
Anubis2005Author Commented:

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

Mike TomlinsonMiddle School Assistant TeacherCommented:
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:

Something like...

    Private Sub Delay(ByVal DelayInSeconds As Integer)
        Dim ts As TimeSpan
        Dim targetTime As DateTime = DateTime.Now.AddSeconds(DelayInSeconds)
            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


    Delay(10) ' hold for ten seconds

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Anubis2005Author Commented:
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.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.