Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Current Timestamp in microseconds

 
neha saxena
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does your OS track the time in Microseconds? Windows is timesliced only to the Millisecond.
 
Dan Cranmer
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See this thread.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic