This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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
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.
Joined: May 24, 2000
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.