Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Current Timestamp in microseconds

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does your OS track the time in Microseconds? Windows is timesliced only to the Millisecond.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See this thread.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic