File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Current Timestamp in microseconds Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Current Timestamp in microseconds" Watch "Current Timestamp in microseconds" New topic
Author

Current Timestamp in microseconds

neha saxena
Greenhorn

Joined: Nov 21, 2001
Posts: 4
Hi,
How can I show the current timestamp in microseconds?
I know it is very easy to show the time in milliseconds using getInstance(), getTime() of Calendar and getTime() of Date class.
and passing time in TimeStamp constructor.
Please let me know how to display the time in microseconds?
Awaiting your reply
neha
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Does your OS track the time in Microseconds? Windows is timesliced only to the Millisecond.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Dan Cranmer
Greenhorn

Joined: May 24, 2000
Posts: 24
The System package has a useful, static method which returns the current time in milliseconds, as described in the java docs. Are you really interested in microseconds? I think that would be very platform specific probably requireing special hardware.
public static long currentTimeMillis()Returns the current time in milliseconds. Note that while the unit of time of the return value is a millisecond, the granularity of the value depends on the underlying operating system and may be larger. For example, many operating systems measure time in units of tens of milliseconds.
See the description of the class Date for a discussion of slight discrepancies that may arise between "computer time" and coordinated universal time (UTC).
Returns:
the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.
Dan Cranmer
Greenhorn

Joined: May 24, 2000
Posts: 24
Not exactly answering the microsecond issue, but an interesting utility for keeping your computer's time correct can be found at:
http://www.boulder.nist.gov/timefreq/service/its.htm
They go on to explain:
On most Win 3.x, 9x, 2000 and Me systems, the time cannot be set more accurately than to the nearest second. It is therefore possible that the time of your system can be wrong by up to +/-0.5 seconds even immediately after you adjust your clock based on data received from one of our servers. In addition, the clocks on many computers can gain or lose several seconds per day, so that even a clock that is set correctly will not stay that way for very long. Windows NT has more sophisticated software support for the clock, but the hardware is usually not any better. If your applications requires that the time on your system must be correct to within +/-1s at all times then you will probably only be able to achieve that level of performance using Win NT and a continuous connection to the Internet. It will be more difficult to realize using other versions of Windows, and you may find that even Win NT does not completely satisfy this requirement.
David Weitzman
Ranch Hand

Joined: Jul 27, 2001
Posts: 1365
See this thread.
 
wood burning stoves
 
subject: Current Timestamp in microseconds