Truncate System.currentTimeMillis()

I'm using System.currentTimeMillis() for a timestamp. I want to truncate the default 13 digits to 10. Any ideas?
Thanks.
tahub

Another question might be WHY?
Why not simply store the entire thing as it is (a long) and it'll
only be 4 bytes instead of 10?
But, if you want the right -most digits dropped, simply divide it.int iSeconds = System.currentTimeMillis() / 1000L;

Similar Messages

  • Converting value from System.currentTimeMillis() to readable format

    hi
    i have in database coumn with values that were stored as result of executing System.currentTimeMillis() in java (=“the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC). i need to convert these values to some human readable format.
    i am able to get year, month and day from these values(value_date) in format "dd/mm/yyyy" but i need hours, minutes and seconds as well.
    select i have for getting years, months and days:
    select (
    extract (day FROM (to_date('01/01/1970 00:00:00000','mm/dd/yyyy hh24:mi:sssss') + value_date/1000/86400))
    || '/'||
    extract (month from (to_date('01/01/1970 00:00:00000','mm/dd/yyyy hh24:mi:sssss') + value_date/1000/86400))
    ||'/'||
    extract (year FROM (to_date('01/01/1970 00:00:00000','mm/dd/yyyy hh24:mi:sssss') + value_date/1000/86400))
    FROM some_table;
    please advice how to improve this select to get something like "dd/mm/yyyy hh:mm:ss"
    thanks

    Note that the result with to_char might still not be what you expect (due to timezone and/or DTS):
    SQL>  CREATE OR REPLACE FUNCTION currenttimemillis
       RETURN NUMBER
    IS
       LANGUAGE JAVA
       NAME 'java.lang.System.currentTimeMillis() return java.lang.long';
    Function created.
    SQL>  select to_char(sysdate, 'dd.mm.rrrr hh24:mi:ss') dt,
           to_char(date '1970-01-01' + currentTimeMillis/(1000*24*60*60),'dd.mm.rrrr hh24:mi:ss') dt2
      from dual
    DT                  DT2               
    04.06.2009 16:44:09 04.06.2009 14:44:09

  • System.currentTimeMillis() problem in Solaris

    hi all
    I have one problem, I have one aplicantion transactional development in java runing in win Nt that up 3 console different + 1 registry console. I have that save the transaction's date in the DB when begin transaction and end transaction. In win NT with Timestamp(System.currentTimeMillis()) is OK. Now in Solaris when up the 3 console, in one, Timestamp(System.currentTimeMillis()) show me the correct time(the time set in the server), but in other console show me other time different (six hour +) and I don't know where takes out this time. I saw the server's timezone and it's ok, and I do in one console >date show me the correct time.
    Anyone help me?
    More information:
    Solaris 8

    Huh?
    currentTimeMillis() returns a number so I can only suppose that on one machine the number is significantly different than on another.
    That means that the times on the machines (nothing to do with java) are different.
    If however you are using Date() to create and display a time, then it means the timezones are different (again nothing to do with java.)

  • Question of System.currentTimeMillis();

    Hi there,
    I got some problem in method "System.currentTimeMillis()" .
    The part of my function is:
         long c= System.currentTimeMillis();
         System.out.println("before time="+c);
              some codes here
    try{new Thread().sleep(1000);}catch(Exception e){} //sleep for additional 1 second
         long b= System.currentTimeMillis();
         System.out.println("after time="+b);
         c=c-b;
         System.out.println("run time="+c);
    the output is:
         before time=1001526336640
         after time= 1001526345985
         run time= -9345
    Couple things I could understand:
    1. b and c are long. in Java they are 8 bytes. in C++ LIMITS.H, long is 4 bytes "#define ULONG_MAX 0xffffffffUL /* maximum unsigned long value */"
    But why time value shows that huge number?
    2. It is strange to get small time after running, the currentTimeMillis() return the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.
    It took me whole day but I couldn't get answer yet. Do you have some idea?
    Thanks

    Im not quite sure what your asking here ?????
    One thing I would like to point out is that you have youre vars a bit mixed in the subtraction
    long b= System.currentTimeMillis();
    System.out.println("after time="+b);
    c=c-b;
    System.out.println("run time="+c);should be
    c= b-c which would equal:9345
    aproximately 9 seconds...
    the currentTimeMillis() return the difference, >>measured in milliseconds, between the current time >>and midnight, January 1, 1970 UTC, Im not too sure this is correct the way you have it stated....
    Its better stated that currentTimeMillis() returns the number of milliseconds that have elapsed, at this current time, since midnight, January 1, 1970 UTC, which is a rather large number..Do the math if youd like.....
    A time yesterday will be smaller than a time today...
    Unfortunately you will need to state your question a bit better in order to get an adequate answer, Please do so and Im sure youll get some answers...

  • Nokia 6030 and System.currentTimeMillis

    Hi
    I'm developing my game for J2ME phones. It works well on a lot of devices. Today I got Nokia 6030 (S40 2nd Edition) and tested my game on this phone. It very strange! Timer works veeeery fast. I made small debug on screen. I made drawString System.currentTimeMillis() and I saw that time goes very fast. On all phones System.currentTimeMillis() increases 1000 per second. On 6030 System.currentTimeMillis() increases 1000000 (or more) per second. Why?!?! On emulator of Nokia 6030 it works well (1000 per second). It very strange. I tested this program on a lot of devices and everywhere it worked well.
    Help me, please...
    MDW

    could be a bug, someone accidentally putting tree zero to much in their code...

  • System.currentTimeMillis() returns time in UTC or not??????

    Hello Friends,
    I want to know that "System.currentTimeMillis()" returns time in UTC or Current Local time
    ie suppose i set my TimeZone (GMT+ 2)
    then statement gives me value in milliseconds by adding 2 hours to the GMT(Is this value should consider as UTC time or we have to subtract and add offset value according to the timezone.
    If time value return by statement is in local time and this is not UTC then is there is any provision in Java to convert local time into UTC time ??
    Regards
    Gaurav

    ejp wrote:
    It returns 'the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.'.Which, of course, as I have tried to explain to the OP (but seemingly not very well) that the "current time" referenced must also be the "current time" in UTC. If the starting point is UTC the ending point is UTC (otherwise it doesn't make any sense to measure it that way). I also attempted to tell him that, when he outputs a String representation of that time (i.e. toString or with a DateFormat Object) that the time he sees will be the time according to the TimeZone set in the DateFormat object, or the local timezone when using toString. But, as mentioned, Date objects (and so, essentially, the long value) is always UTC (relevant to the starting point, of course).
    A quote from the Date Class
    Although the Date class is intended to reflect coordinated universal time (UTC), it may not do so exactly, depending on the host environment of the Java Virtual Machine.which I take to mean that Date is always UTC in so far as the host environment is capable of it.

  • System.currentTimeMillis() going backwards!!!

    Hi,
    The following program runs a loop, each iteration measuring the time, and ensuring the new time is later than the last measured time.
    I run it like this:
    java -cp . Test 500 1
    My JVM is this:
    ahl84:/nfs/ahl16/users/is/djepson/work/backwards $ java -version
    java version "1.3.1.01-release"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1.01-release-010816-12:37)
    Java HotSpot(TM) Server VM (build 1.3.1 1.3.1.01-release-010816-13:34-PA_RISC2.0 PA2.0, mixed mode)
    On one of our production machines, this program actually reaches the ERROR line - i.e. time is SEEN to go backwards.
    The problem also happens (although less frequently if I use a 0 for the sleep value - i.e. I am not forcing rescheduling on the main thread.
    Please, anyone any ideas???
    The machine in question has 2 CPUs if thats any help, but I can run it on other multi-CPU machines, seemingly without problem.
    public class Test
       public static void main( String[] args )
          for ( int i = 0; i < args.length; i++ )
             System.out.println( "arg[" + i + "]=[" + args[i] + "]" );
          if ( args.length != 2 )
             System.out.println( "Usage:" );
             System.out.println( "java -cp . Test [iterations] [delay (ms)]" );
          else
             Integer iterations = Integer.valueOf( args[0] );
             Integer delay = Integer.valueOf( args[1] );
             Test t = new Test( iterations.intValue(), delay.intValue() );
             t.go();
       public Test( int iterations, int delay )
          _iterations = iterations;
          _delay = delay;
          _errors = 0;
          _lastTime = System.currentTimeMillis();
       public void go()
          System.out.println( "START : Iterations=[" + _iterations + "], delay=[" + _delay + "], time=[" + _lastTime + "]" );
          for ( int i = 0; i < _iterations; i++ )
             long now = System.currentTimeMillis();
             if ( now < _lastTime )
                System.out.println( "Time sequence ERROR, i=[" + i + "], last=[" + _lastTime + "], now=[" + now + "]" );
                _errors++;
             else
                System.out.println( "Time sequence OK,    i=[" + i + "], last=[" + _lastTime + "], now=[" + now + "]" );
                _lastTime = now;
             if ( _delay > 0 )
                try
                   Thread.currentThread().sleep( _delay );
                catch ( InterruptedException e )
                   e.printStackTrace();
          System.out.println( "FINISH : Time=[" + _lastTime + "] errors=[ " + _errors + " / " + _iterations + " (" + ((float)_errors / (float)_iterations * 100) + "%) ]" );
       long _lastTime;
       int  _iterations;
       int  _errors;
       int  _delay;

    I think You may be running into an os/hardware problem. The
    System.currentTimeMillis() returns the number of milli secs since
    sometime in 1970. However the actual resolution of it depends on the operating system and hardware. Its possible that the thread is being
    allcoated to different procs on your machine (after sleeps especially
    and sometimes anyway) and the OS call used by java returns different
    values.
    for some reason I have a hunch that this isn't a java problem as such.
    maybe os/ maybe hardware/ maybe interation of java with both.
    try forcing the VM to run on one processor only.
    matfud

  • Help with code for System.currentTimeMillis()

    I need to time how long it takes to do various sorts (selection sort, insertion sort) and was instructed to use System.currentTimeMillis() to accomplish this. Please take a look at the code below and let me know what is wrong. I can get the file to complile but it does not record the time it takes to run the sorts. I'm pretty sure my error is in the below section of code. In order to save space, I've only pasted the snippit of code for this particular function. Let me know if I need to paste more code. Thanks in advance.
    case 5:
                             System.out.print("Enter the value to look for: ");
         val = scan.nextInt();
         time1 = System.currentTimeMillis();
         loc = list.linearSearch(val);
         time2 = System.currentTimeMillis();
                             totalTime = time1 - time2;
                             System.out.println("Total time for this search is: " + totalTime);
         if (loc != -1)
                                  System.out.println("Found at location " + loc);
         else
                                  System.out.println("Not in list");
         break;
                             

    It could be that it isn't actually doing anything
    though. Either because the data is poorly choosen or
    because it isn't actually sorting due to a bug.The name of the method being timed is "linearSearch". That's a really poor name for a method that is supposed to be sorting. But from other aspects of the code I would guess that it is doing a linear search of an array, looking for a particular integer. Even if the integer isn't in the array, comparing 20,000 integers is a trivial exercise.
    People don't realize just how long a millisecond is for a computer. If you have a 1 GB processor (not uncommon these days) then you can do one billion (one thousand million) operations per second. That's one million operations per millisecond. So chances are, even realizing that there's a whole lot of overhead in a high-level language, the OP's code runs in less than 1 millisecond.

  • System.currentTimeMillis() not accurate on Windows ?

    Hi,
    JVM : 1.4.2_03-b02
    OS : Windows XP
    processor : XEON 2.4 GHz
    Following test fails with 62.5 error percentage.
    Is it due to windows failing to give time on a millisecond level ?
    Or is there another reason ?
      public void testSleep() throws Exception {
        int total = 1000;
        int errors = 0;
        for ( int j = 0; j < total; j++ ) {
          long start = System.currentTimeMillis();
          Thread.sleep(5);
          long end = System.currentTimeMillis();
          if ( end < start+5 ) {
            errors++;
        Float errorPercentage = new Float( errors*(float)100/total );
        assertEquals( new Float(0), errorPercentage );
      }Regards, Tom.

    The millisecond level of precision is only a possibility provided by the API, the OS does not forcibly provide it.
    But Thread.sleep will not be absolutely precise, it is the most likely culprit.

  • Weblogic 9.2 , JDK 1.5 and System.currentTimeMillis()

    Hi
    I am using Weblogic 9.2 and JDK 1.5
    In my application I have System.currentTimeMillis().
    But when I use WL9.2 the time is getting 15 minues faster.
    For eg. if system time is 10.00 am , in WL9.2 it reads as 10.15 am ,so around 15 minutes faster
    Any thought s o nthis issue..
    How can configure this?
    Thanks in advance
    -Binu

    This is not a certified combination -- it has probably never ever been tested is my guess as 9.0.3 was released back in 2001(2?) (can't recall exactly) which was well before JDK5 was released.
    You can generally change the JDK used to run an OC4J instance by changing the JDK path in the opmn.xml file.
    But please note that this is not supported, almost certainly not tested (at least by us) so the outcome is not clear.
    The first release we support JDK5 with is 10.1.3 -- is doing an upgrade a possibililty for you?
    -steve-

  • System.currentTimeMillis() and Date()

    Hi,everybody
    What is the difference beetween System.currentTimeMillis() and Date()?
    Regards,
    Michael

    Michael,
    System.currentTimeMillis()  -- current date represented as number of milliseconds after/before Jan 1, 1970
    java.util.Date -- object that encapsulates date, when constructor called without arguments then it's current date. Note that almost all methods of this class are deprecated while it was designed only for Grigorian calendar. To get specific day/month/year from java.util.Date use java.util.Calendar.
    Valery Silaev
    SaM Solutions
    http://www.sam-solutions.net

  • Difference between using new Date() and new Date(System.currentTimeMillis()

    Hi All,
    I have seen many open source api's where they are updating dates with the following code
    new Date(System.currentTimeMillis())
    when i print the new Date() it prints the same
    what is the difference between using new Date() and new Date(System.currentTimeMillis()) ??
    Thanks,
    J.Kathir

    when i print the new Date() it prints the same
    It does because of backward compatability. This constructor exists in version 1.3.1 but not in newer versions.Really ? Please point me to where you read that.
    API doc 1.5 : new Date() (still there, not even deprecated)
    A quick look at the code for this constructor:    /**
         * Allocates a <code>Date</code> object and initializes it so that
         * it represents the time at which it was allocated, measured to the
         * nearest millisecond.
         * @see     java.lang.System#currentTimeMillis()
        public Date() {
            this(System.currentTimeMillis());
        }

  • 1 month difference between OS time and System.currentTimeMillis()

    Hi all:)
    System.currentTimeMillis() give a time 1 month ago. If any one have idea what is wrong?Others programs give the right time.
    I tested on Windows XP Pro and Linux end the result is wrong on both OS.
    Thank you in advance.

    posman@linux:~/ivan> uname -a
    Linux linux 2.6.4-52-default #1 Wed Apr 7 02:08:30 UTC 2004 i686 i686 i386 GNU/Linux
    posman@linux:~/ivan> cat x.java
    public class x {
    public static void main(String args[]) {
    System.out.println(new java.util.Date());
    posman@linux:~/ivan> javac x.java
    posman@linux:~/ivan> date;java x
    Mon Feb 14 10:18:02 CET 2005
    Mon Feb 14 10:18:02 CET 2005

  • Does System.currentTimeMillis() cater for daylight saving

    My question is does System.currentTimeMillis by any means cater for the daylight savings time or in the other case when clocks are moved backwards it repeats it self???????
    Its pretty confusing isnt it?

    the whole problems with the currentTimeMillis is that it calculates the offset from the System clock - System TimeZone Offset
    if the System uses Manual DST or the auto DST is not checked (Windows)
    The the user of the system changes manually the clock and the calculation
    current millis will be wrong one hour
    for example I am in GMT + 2 + DST(1)
    GMT is 1200
    Local OS shows 1400, and I manually change it to 1500 (DST check box is not checked
    the Java will report GMT time 1300 (1500 - 2:00)
    whic is wrong.
    There is no indication wether this check box is checked or not
    If anyone knows how to find out if its checked please tell all

  • System.currentTimeMillis() not respecting system clock

    How does System.currentTimeMillis() work? I thought it checked the system clock. But I have an application that monitors the clock and I try to catch changes in it (for instance if the user changes his/her clock during runtime). But the System.currentTimeMillis() seems to ignore the time changes of the sytem clock. Any ideas?

    I had already done that. That is why I posted. I
    could have sworn it worked from previous experience,
    but I am not seeing it work now...The following code:import java.io.*;
    import java.util.*;
    public class TimeDemo {
        public static void main(String[] args) {
            try {
                InputStreamReader isr = new InputStreamReader(System.in);
                BufferedReader br = new BufferedReader(isr);
                System.out.println(System.currentTimeMillis());
                br.readLine();
                System.out.println(System.currentTimeMillis());
            catch (Exception e) {
                System.out.println(e);
    }Produces the following output:
    $ java TimeDemo
    1120149951371
    1117644363468 You'll note that time appears to have gone backwards - but in fact I set the clock back during the readLine block. So I think it does respond to changing the clock (at least under Solaris on a SPARC with Java 1.5).

Maybe you are looking for

  • ASDM-713

    hi i´m using a macbook OS 10.8.4 for configuring ASA´s with ASDM since years. now i upgraded one of my ASA´s to 9.1.2 with ASDM 7.1.3 and i can´t launch ASDM anymore. I tryed chrome, firefox and safari. i upgraded java to 7.4 ...nothing -> i still do

  • XI Alert - How to put messageid into Subseq. Activities Link

    Hi, I have control step to throw alert whenever error occur in the BPM. How can i put the messageid into the Subseq. Activities link so the user can only click the link and open the message in the message monitoring. I gave the URL below in the subse

  • Hiding the default tool tip in DVT:Gauge status meter

    Hi, In my page, I have a DVT:Gauge(Status Meter) with 3 thresholds. Lets say, ThresholdMaxValue for the first is 1.0 and the second is 2.0 and the third is 3.0. Whenever I mouse over on the second threshold range, it says "Between 1.0 and 2.0". Is th

  • Problem with quotation /salesorder

    hi, in one sales area we have material like m1,m2,m3...etc and customer like c1,c2,c3......etc i could't create quotation/order for  some of them combination .i am getting empty or null  as order number. can u pls tell me the reason regards Guru

  • My Notes are blank on my MacBook Pro Retina display

    My Notes show up but when you click on the Note it's blank. The new Notes that I make have the title and the information in the Note.