Solved

Timestamps and the number of milliseconds since midnight 1970

Posted on 2007-04-03
4
2,399 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 85

Accepted Solution

by:
Mike Tomlinson earned 500 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

749 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