Time difference in inlclueding millisenconds

I am trying to get the time difference in millisends.
currently i am using following logic and found it is not giving accurate result.
java.util.Date d1 = new java.util.Date();
java.text.SimpleDateFormat f1 = new java.text.SimpleDateFormat("HH:mm:ss SSSSSSSSSSSSS");
Date today1;
String dateOut1;
DateFormat dateFormatter1;
// DateFormat formatter;
Locale currentLocale1 = new Locale("en", "US");
dateFormatter1 = DateFormat.getDateInstance(DateFormat.DEFAULT, currentLocale1);
today1 = new Date();
double sec = today1.getSeconds();
System.out.println("nano secnonds : "+today1.getTime()+"<==="+today.getTime());
System.out.println("milli sec : "+today1.getTime()+"<==="+today1.getTime()/1000000);
System.out.println("date : "+today1.getDate()+"<==="+today.getDate());
System.out.println("hours : "+today1.getHours()+"<==="+today.getHours());
int min1 = today1.getMinutes() - today.getMinutes();
System.out.println("difference min : "+min1);
int sec1 = today1.getSeconds() - today.getSeconds();
System.out.println("difference seconds : "+sec1);
long time1 = today1.getTime()- today.getTime();
System.out.println("difference time: "+time1);
System.out.println("date difference : "+today1.compareTo(today)+"<====");
dateOut1 = dateFormatter1.format(today1);
long leftVal =0;
int seconds = sec1 - 1;
long timeval = 1000 - time1;
System.out.println("timeval : "+timeval+"<===");
if (time1 > 1000)
leftVal = 1000 - time1;
seconds = sec1;
else
leftVal = time1;
seconds = sec1;
Can anyone help in getting the time difference in hours, minutes, senconds and milliseconds
Sumanth

Could you please tell me is there any function which can simply returns me the time diffrence,That is the time difference.
If you want to display the difference in a different format then do so....
long time1 = ....
long timesecs = time1/1000;
long hours = timesecs/3600;
long minutes = (timesecs - hours * 3600)/60;
long secs = (timesecs - hours * 3600 - minutes * 60);
long millis = time1 % 1000;
Please keep in mind that the above is for display purposes the real difference is in time1.

Similar Messages

  • How to calculate the % of time difference between different state

    Hi there,
    The below query returns the follwoign outptut. I need to calculate the % of time period that a specific state ( state ex: open or closed or all report )exists.
    I have to find the time difference between the 2 states . How could I do that ?
    The first row shows null for the previous state . How could get actual previous state for the first row?
      SELECT si.station_name,
                    vppstation.avi_control_state_code.STATE_SHORT_NAME,
                    ash.state_id ,
                    lag(ash.state_id) over (order by ash.STATE_EFF_DATE desc) previous_state,
                    TO_NUMBER(TO_CHAR(ash.state_eff_date, 'SSSSS')) "periods in sec",
                    TO_CHAR(ash.state_eff_date, 'dd-mon-yyyy hh24:mi:ss am') "Date"
               from vppstation.avi_state_history ash
    left outer join vppstation.avi_control_state_code
                 on ash.state_id = vppstation.avi_control_state_code.state_id
    LEFT OUTER JOIN vpproadside.stations_installed si  
                 ON ash.station_id = si.station_id               
              where ash.state_eff_date >= to_date('28/02/2010', 'dd/mm/yyyy')
                and ash.state_eff_date <= to_date('03/03/2010', 'dd/mm/yyyy') ;
           group by si.station_name
                         ash.state_id
           order by ash.state_eff_date asc ;
    STATION_NAME                   STATE_SHORT_NAME STATE_ID               PREVIOUS_STATE         periods in sec         Date                   
    IRDNCST02                      Open             1                    NULL                  85166                  01-mar-2010 23:39:26 pm
    IRDNCST02                      All Report       3                      1                      85159                  01-mar-2010 23:39:19 pm
    IRDNCMT01                      Closed           2                      3                      81376                  01-mar-2010 22:36:16 pm
    IRDNCST02                      Open             1                      2                      78723                  01-mar-2010 21:52:03 pm
    IRDNCST02                      All Report       3                      1                      76023                  01-mar-2010 21:07:03 pm
    IRDNCMT01                      Open             1                      3                      55922                  01-mar-2010 15:32:02 pm
    IRDNCMT01                      Closed           2                      1                      54931                  01-mar-2010 15:15:31 pm
    IRDNCHA01                      Closed           2                      2                      41291                  01-mar-2010 11:28:11 am
    IRDNCAS01                      Open             1                      2                      38847                  01-mar-2010 10:47:27 am
    IRDNCAS01                      All Report       3                      1                      37947                  01-mar-2010 10:32:27 am
    IRDNCST02                      Open             1                      3                      35332                  01-mar-2010 09:48:52 am
    IRDNCST02                      All Report       3                      1                      32632                  01-mar-2010 09:03:52 am
    IRDNCST02                      Open             1                      3                      31502                  01-mar-2010 08:45:02 am
    IRDNCST02                      All Report       3                      1                      28802                  01-mar-2010 08:00:02 am
    IRDNCHI01                      Open             1                      3                      25368                  01-mar-2010 07:02:48 am
    IRDNCHI02                      Open             1                      1                      23939                  01-mar-2010 06:38:59 am
    IRDNCMT01                      Open             1                      1                      20696                  01-mar-2010 05:44:56 am
    IRDNCCH02                      Open             1                      1                      13452                  01-mar-2010 03:44:12 am
    Edited by: Indhu Ram on Mar 11, 2010 1:34 PM
    Edited by: Indhu Ram on Mar 11, 2010 2:20 PM

    If you look at the table which is output of the given query , there is column called "STATE_ID" It shows the current state ie open or closed or all report.
    The column 'PREVIOUS_STATE' shows the state before the current state. .In the table in 2nd row in previous_state column there is state_id = 1 (open)which is the state before 'all report state'

  • How to measure time difference between zero crossing of a sine wave and rise time of a pulse on a same graph?

    I have a 50Hz sine wave and a pulse signal on a same graph. The phase difference between two is between 0-90 degrees.
    Now I need to calculate the time difference between (when the sine wave crosses zero volts) and (when the pulse rises). The frequency will stay approximately same for both signals.
    The application is for a three phase generator. In simple words, when the time difference between the zero-crossing of sine wave and the pulse rises increases, that means that the load on the generator has increases.
    I am a beginner user of LabView (version 9, 2009), maybe it is a very simple problem but I've been pulling my hair out for the last few days and coudln't figure anything out. Any help would be greatly appreciated. I am using DAQ USB-6008 to measure these voltages and pulse from the generator and a sensor
    I have attached a jpg (a graph that i just made with excel to explain). The time 't' is what I am trying to measure
    Cheers
    Awais 
    Message Edited by awais.h on 03-30-2010 11:20 PM
    Message Edited by awais.h on 03-30-2010 11:21 PM
    Solved!
    Go to Solution.

    Hi
    Thanks for the code but I'm afraid it won't work. Like you said the probability of choosing a value that is on both graphs may not happen. This is something that I would like the code to do automatically.
    But I did use the previous code posted and made some modifications to it and it seems to work perfectly. Now the next thing is to be able to get just that one value that tells you the first time difference.
    Here is what I get using that code.
    As you can see from the t Values. I only need the one that is highlighted. If there is a way to filter out the rest it would be great.
    I was thinking of a while loop and as soon as the value is higher than 3E-5 it would store the number and stop the loop, but I'm not too familiar with arrays in labview.
    Here is the the code modified.
    As you can see, it wasn't that big of a modification and it still is your code.
    I will keep trying.
    Thanks for the help
    Attachments:
    FinalShockSpeed.vi ‏55 KB

  • Lost connection detection time difference

    Having a problem understanding why a broken JDBC connection is detected under Windows much quicker than it is under Linux.
    I have an process that opens a connection to MSSQL using JDBC, a Stored Procedure is then executed and the result set
    processed, this execute step is repeated every 60 seconds or so. If any exception is thrown then resources are closed, sleep
    for 60 seconds, the connection is reopened (if fails then sleeps and repeats), once reopened the process continues. There is logging throughout
    the above steps.
    On Windows Vista 64bit Sun Java platform the process runs fine, if I deliberately break the connection (stop MSSQL service), the process
    logs a problems within 60 seconds and starts handling the error, when the MSSQL comes back then within 60 seonds the connection is remade
    and the process continues as expected.
    Under Ubuntu 10 64bit both Sun and OpenJDK the process runs fine, until the connectionis broken, as it takes about 17 minutes for the exception to be thrown
    for the broken connection (stopped MSSQL) to be detected, as opposed to under Windows taking seconds. Once detected then the process works as expected, retrying
    and reconnecting as it should.
    The libs and code used are the same the only difference between the windows and linux versions are the logging path parameter, have tried with different versions of Java
    and with different MSSQL JDBC drivers.
    What could be the reason for the time difference in the lost connection detection between Windows and Linux? Any help tips would be most welcome.
    Thanks.

    The connection is only made once and used throughout, it is only closed if there is a problem. This runs absolutely fine with logging for weeks, the execute and processing take millisecondsIt is pointless to keep the connection in that situation. Create it every time.
    Doing that might even fix your problem. But regardless you should still not keep it.
    Have jujst checked the timings and if the db connection is broken the on Linux (Ubuntu) the exception generated by step 4. takes up to 15 minutes 35 seconds to move on to step 7. on Windows though it is instant, there is a log message output prior to the execute statement this outputs then the exeception logged.You have an existing connection.
    Then you attempt a request which I am guess takes 17 minutes to timeout. (That happens because you are testing by stopping the server.)
    That is the problem.
    First verify the connection url. It might have timeout values in it.
    If not then the next most likely cause is that someone changed the OS (not java) TCP timeout values. Bad idea if they did. And the only way to fix is to change them back to something reasonable. You can code around this by using two threads. One that sets a timer and the other that runs the request. If the timer fires then attempt to cancel the request (see the jdbc api.)

  • How to find out time difference between 2 consecutive characters coming in

    Hi
    Data is coming on serial port and m taking this data in a input stream.I need to know the time difdference between consecutive characters.Any ideas?

    What do you mean? If you meassure the time between two characters, you want to calculate how accurate it is? First you would need to find out how accurate the System.currentTimeMillis is on the platform you run on. That may be easy
    long start = System.currentTimeMillis();
    long end;
    while ((end = System.currentTimeMills()) == start);
    long delta = end - start;But sometimes (on win98) it reports 50, other times 60. So its not quite accurate. But you could redo that test a couple of times and take the avg or the max.
    Then if you get a time difference of 0ms between two characters, you know it will be somewhere 0 and 60ms. If you get 60ms between two characters, you know it will be somewhere between 0 and 120 ms. It's +/- delta seconds accurate.
    Would this be a way to calculate the percentage accuracy: 100.0-100.0*delta/(time+delta)
    Still better to meassure the time over more than just 2 characters unless it is a very slow stream.

  • Execution time difference between SELECT & UPDATE statement in JDBC Sender.

    Hi Experts,
    In my scenario, I have used the JDBC Sender Adapter with the SELECT and UPDATE statement.
    Now the problem is in between the execution of Select and update statement, few more entries are coming in the same DB Table.
    So result of this is updation take place for those entries which are not even picked up by the select statement.
    Can we avoid this execution time difference between the SELECT & UPDATE statemet on JDBC Sender side???
    Thanks & Regards
    Jagesh

    Hi
    Use serializable option in additional parameters, now all new entries would also be updated.

  • How to find the date and time difference in InfoPath 2013?

    Hi All,
    My date and time format is like: 2013-12-24T10:47:38 and have three fields Start date, End date and Actual time taken.
    If start date and end date filled then actual time taken field should automatically should fill, for example 2 days 12 hours 48 min 3 sec.
    How to achieve this?

    Hi Sam,
     I believe we had discussed the same issue in the below thread. Can you please refer the below one?
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/d93e16ff-c123-4b36-b60b-60ccd34f6ca7/calculate-time-differences-in-infopath?forum=sharepointcustomizationprevious
    If it's not helping you please let us know
    Sekar - Our life is short, so help others to grow
    Whenever you see a reply and if you think is helpful, click "Vote As Helpful"! And whenever
    you see a reply being an answer to the question of the thread, click "Mark As Answer

  • How to get exact date and time difference?

    Hi,
    When i am using the below sql statement:
    SELECT (TO_DATE('7/27/2006 05:00:15 PM','MM/DD/YYYY HH:MI:SS PM') - to_Date('7/27/2006 8:30:13 AM','MM/DD/YYYY HH:MI:SS AM')) * 24 hours FROM DUAL;
    the output is:
    Hours
    8.50055555555556
    But Actually it is 8.30
    So how can i get exact days and time difference between two dates in Oracle?
    Thanks....
    Regards,
    Suman Sakinala
    Edited by: SSN on Sep 19, 2008 1:27 AM

    Or more clearly (this time I have my date_from and date_to the right way around hehe!)
    SQL> ed
    Wrote file afiedt.buf
      1  WITH t as (select TO_DATE('7/27/2006 05:00:15 PM','MM/DD/YYYY HH:MI:SS PM') as dt_to,
      2                    TO_DATE('7/27/2006 08:30:13 AM','MM/DD/YYYY HH:MI:SS AM') as dt_from FROM DUAL)
      3      ,d as (select (dt_to-dt_from)*24 as diff_hrs from t)
      4  -- end of dates
      5  SELECT TRUNC(diff_hrs) as hours
      6        ,TRUNC(((diff_hrs) - TRUNC(diff_hrs))*60) as mins
      7        ,TRUNC(((((diff_hrs) - TRUNC(diff_hrs))*60) - TRUNC(((diff_hrs) - TRUNC(diff_hrs))*60))*60) as secs
      8* FROM d
    SQL> /
         HOURS       MINS       SECS
             8         30          2
    SQL>

  • Send the same   message to two receivers with some  time difference..

    Hi
      I want to send the same message to Two receivers  with the slight time difference.. becuase  but not at the same time.. if the same time means.. just we can  specify the two receivers in the one receiver determination..
       but  if i want to send the   same message to Two  reveivers with the time difference means..(after sending the  message to first receiver.. after  some time gap.. i need to send the  message to second receiver..
      this type of scenarios how can we do.. is it possible to do with out BPM...  please suggest me the solution..
    Thanks
    Jain .P

    Hi Jain,
    With BPM you can easily do it.
    i am giving you the steps:
    1)first add a receive strep to get your message
    2)then, put a receiver determination step with a multiline receiver container element assigned to its Receivers property.
    3)then, put a block in dynamic mode(ie. ForEach/ParForEach mode) and assign the multiline receiver container element to its multiline element and assign a simple(single line) receiver container element to its current line property.
    4) add a send step within the block, choose Receivers List in its Receiver From property and choose the current line receiver element in its Receivers property.
    5) then add a wait step in the BPM, in its type select Wait Specified Time Period and then mention the duration in your desired time unit.
    **Reward points if helpful...
    --Sankar Choudhury

  • Stopping a while loop using the time difference of two tick counts

    Hi Guys,
    I'm currently writing a code which test how long does it take for a formula node to perform its operation. The program uses a while loop to perform the calculation, and the program stops after calculating when tick count has reached 10 seconds. The program then displays the number of iterations it does in 10 seconds. 
    So initially I created 2 frames of sequence structure. In my first frame I have my initial tick count, and in my second frame I have my final tick count and the while loop. I used the subtract function and divide the output by 1000 to get the time difference. Then using the comparison function, I set if output > 10 then the program should stop, to do this I linked the output of the comparison function to the stop button inside the while loop. 
    However, when I tried to run the code, the program just didn't run. Hence I created a similar program which puts the last tick count in new frame sequence. When I ran this code, the program never stopped. 
    Do you guys have any idea what went wrong with my codes.
    Thank you!
    Erry
    Solved!
    Go to Solution.
    Attachments:
    1. Tick Count.vi ‏27 KB
    tickcoun2.vi ‏27 KB

    Dataflow!
    In both VI's the stop terminal of the while loop is controlled by a boolean whose source is ouside of the while loop.  So that loop will either run once, or run forever, depending on the value of the boolean that is calculated before the loop starts and shows up at the tunnel going into the loop.
    I would recommend looking at the online LabVIEW tutorials
    LabVIEW Introduction Course - Three Hours
    LabVIEW Introduction Course - Six Hours

  • Calendar time difference

    Hi, I have a problem, when I sync my Nokia 6300 with my Outlook calendar the appointment time gets changed on my phone to an hour earlier somehow. It has only recently started doing this, it was fine before. I would appreciate any suggestions. Many thanks

    check to see that both your computer and your phone are set in your correct time zone. If they are not the same the phone could be trying to make up for the time difference by altering the alarm times by an hour.
    You do not say where you are so I cannot give you your exact time zone.
    Have you removed your battery from your phone recently and had to reset the time perhaps? This might have caused the problem
    iPhone 5 32GB
    MacBook Pro Retina 15" Mac OS X Mountain Lion 10.8.4

  • Calculate time difference in Labview from excel file

    I am reading in values from a excel files, the file contains date and time data in one cell, then either an On or Off value in the cell next to it. I would like to find the time difference between the on and the off cycles. The VI I have so far brings in the Excel file but I don't know how to subtract the dates. Any help would be appreciated. I have attached the vi and hopefully I can attach and example excel file.
    Attachments:
    Hobo Import.vi ‏156 KB

    Hi Bryan!
    I made a small VI (in LabVIEW 7.1) that converts to strings (of your format) to timestamp datatype and then subtracts them resulting in a difference measured in seconds. There might be a more optimal way to do this in your application, but I thought I'd at least try to contribute. Also, notice that there is a Y3K bug in there :-)
    Hope this helps!
    Travis H.
    National Instruments
    Travis H.
    LabVIEW R&D
    National Instruments
    Attachments:
    FormattoTimeStamp.vi ‏38 KB

  • Time differences between camera and iMovie

    Hi,
    When I import footage from my Mini-DV camera into iMovie I am seeing a difference between the time displayed on the tape and time displayed in iMovie. The camera says 48 seconds while iMovie says 44 seconds. I thought that it might be related to the framerate of the video in iMovie, but I have changed this to 25 fps which matches the video camera and am still seeing a different time. The framerate needs to be perfect as the footage is going to be shown side-by-side with a animated graph which builds with time.
    Does anyone have any idea what could cause this time difference?
    Thanks

    < scratching head > we had something about a NTSC/PAL issue.. hmm.. ?
    if possible, open an existing PAL project (window titles says DV-PAL), save it under a diff. name, import into that project, delete the not wanted parts..
    another option is, quit iMovie, delete ~/Library/Preferences any com.apple.iMovie.plist file.. relaunch iM.. that 'resets' iM... sometimes, it starts to stumble..

  • Time difference between physical and logical standby

    Hi,
    I have just been tasked on getting some info and setting up dataguard for some users for read-only/reporting purpose.
    The 3 questions I am being asked are:
    1. What is the time difference in applying changes from primary to physical standby compare to logical standby
    2. What is the overhead maintenance of having a standby database?
    3.What latency is involved?
    I will be glad to have your input on this.
    Thanks

    Hi,
    Physical Standy where its a read only DB.
    Logs are applied.
    Logical Standy where it can be Read / Write DB and the logs are applied in terms of SQL Statements.
    Thanks & Regards,
    Pavan Kumar N

  • Standard function for returninf time difference in days and hours.

    Hello all,
                Can somebody tell me whether there exists some standard function module which can calculate the time difference and returns the calculated time in the form of days and hours ?
    e.g. the time difference between the date 1.12.2007 from 7.00 pm to the date 1.1.2008 till 9.00 pm is
    30 days  and 2 hours or 30 : 2.
    answer as soon as possible.
    Thanks and regards,
    me

    Thanks a lot ya..
    thats an absolutely correct solution to my problem.  )

Maybe you are looking for

  • To comapre a single date with multiple dates

    Hi All, I am using fetch xml report in which there are two table Opportunity and activity One Opportunity with have multiple activity Opportunity has a field  called new_dateofapplication and Activity has a field called StartDateActivity which have m

  • Coldfusion 11 error with cflayout

    0 down vote  favorite   I have some applications developed on older CF versions (9&10) and in anticipation of a hosting system migrating to CF11 and started doing some testing with a CF development platform on Windows 8 with Apache 2.4. I have found

  • Strange sound coming through external speakers

    On my 2010 iMac there is a problem when *no audio* is coming out through the external speakers (connected via the headphone port). If i play any sound (even change the volume and get the 'blip' sound) and then go back to silence, after 5 - 10 seconds

  • Transfer Routine required

    Hi, I am getting the Alpha Numeric (for example:150DD say)data for the field 0SALESEMPLY into the infosource 2LIS_11_VAHDR, but the data type for 0salesemply is NUMC in the info source. Because of this data type(NUMC) the data for this filed is loadi

  • Help Getting Started with Bridge Scripting

    I'm trying to learn enough about scripting to understand/modify some simple Bridge scripts, but can't seem to find the proper documentation. I have downloaded the Bridge SDK, have the documents for Adobe Intro to Scripting, Adobe Bridge CS5 javascrip