My Quotes


When U were born , you cried and the world rejoiced
Live U'r life in such a way that when you go
THE WORLD SHOULD CRY






Showing posts with label Nano seconds in Java. Show all posts
Showing posts with label Nano seconds in Java. Show all posts

Tuesday, October 8, 2013

Nano seconds in Java

  1. Get backport-util-concurrent.jar from nexus
<dependency>
<groupid>backport-util-concurrent</groupid>
<artifactid>backport-util-concurrent</artifactid>
<version>3.1</version>
</dependency>
  • code snippet
   import java.util.concurrent.TimeUnit;
long timeInMillis = System.currentTimeMillis();
  • You can use query to get the DB time
select extract(day from(systimestamp - to_timestamp('1970-01-01', 'YYYY-MM-DD'))) * 86400000 + to_number(to_char(sys_extract_utc(systimestamp), 'SSSSSFF3')) current_time_milliseconds
    from dual;
  • Timestamp dbTimeStamp = result of above quey...
long nanos = TimeUnit.SECONDS.toNanos(System.currentTimeMillis());
dbTimeStamp.setNanos((int) (nanos % 1000000000));