Computing.Net > Forums > Programming > System time in VB

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

System time in VB

Reply to Message Icon

Name: rainchild19
Date: August 14, 2002 at 07:18:40 Pacific
Comment:

Hi,

Does anybody know how to either get or calculate the system time in milliseconds from a certain date? What I'm basically looking for is the same thing the of the function System.currentTimeMillis() in Java.

Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: Jeff J
Date: August 15, 2002 at 10:42:50 Pacific
Reply:

This post is sliding by because there is no simple answer. Java was originally based on the traditional Unix convention of absolute time, sometimes called the "epoch". Dates are actually relative to Jan 1, in the year 1970 (at midnight). You can accumulate the number of seconds in a 32-bit integer, but not milliseconds. Java uses larger objects to hold milliseconds.

Fraction-of-a-second absolute date resolutions became popular with later OS's, such as Windows, as higher clock speeds and larger integers became more popular. Even still, although Windows natively supplies millisecond values, actual resolution is almost never that accurate, regardless of platform. Absolute times are somewhat haphazard on most machines, to avoid massive calculation overhead. Thus, absolute times are almost useless for timing purposes beyond a second resolution. COM (and hence VB5/6) thus does not normally bother beyond the second.

To complicate matters, Windows does not store absolute system dates relative to 1970, but as distinct integers for year, month, day, second, and milliseconds (guestimated). Filetimes are relative, however to the year 1601, in 100-nanosecond intervals, and will be valid for centuries to come.

The Java use of milliseconds since 1970 is somewhat of a compromise, that can be calculated on either Windows or Unices (the most common platforms it runs on). If you are trying to time something, I strongly recommend you use relative time, such as clock ticks, which is common to most platforms, and gives great performance and precision. If you want to simply store absolute dates into a universal integer, then you will have to calculate.

If you can give me a better idea of what your needs are, perhaps I can better answer your question.

Cheers


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: System time in VB

Date and time in VB www.computing.net/answers/programming/date-and-time-in-vb/9009.html

Timing in VB www.computing.net/answers/programming/timing-in-vb/5537.html

On Error in VB www.computing.net/answers/programming/on-error-in-vb/9139.html