Measuring time in milliseconds

Hi,
I have to measure time in millisecond between two user events in Applet, so I did this:
Date startDate = new Date();
// Users answer some questions
Date endDate = new Date();
int timeElapsed = endDate.getTime() - startDate.getTime();It was all fine, until the users figured out to cheat this system: they changed their computer's clock before answering the final question.
So, is there any way to measure time in milliseconds and its independent from the computers clock?
Thanks!

meikop wrote:
Thanks!
I have a client - server application indeed.
So as I understand, there's no good solution on the client (applet) side only - there's no way I can measure exact time and not be worried about clients computer clock? Any theoretical explenation ?
Otherwise I have to mesure the time on the server side - I had it implemented some time ago:), but the clients started to complain about network latency etc so I decided to measure the time on the client side - not so good idea after all :)?
I'll probably have to calculate each clients average network latency and so on...
One can handle the client side clock being changed by the user by keeping a 'correction' in the client which is the difference between the client clock and the server clock. This way one only needs to update the correction at intervals - I use 1 minute update in my Bridge game. I don't need millisecond accuracy but it would not seem to be too difficult to correct for the network latency in calculating the correction.
P.S. You would do better to use System.currentTimeMillis() rather than construct a Date() object which actually uses currentTimeMillis() behind the scenes.

Similar Messages

  • Measuring time in smaller unit than millisecond

    I need to be able to measure time to a higher precision than Java provides. Is there any way that I can achieve this using a windows platform preferably?

    Here is the code JNI C code:
    JNIEXPORT jdouble JNICALL Java_Win32Native_queryPerformanceFrequency (JNIEnv *env, jobject obj) {
         LARGE_INTEGER lFrequency;
         ::QueryPerformanceFrequency(&lFrequency);
         return (jdouble)lFrequency.QuadPart;
    JNIEXPORT jdouble JNICALL Java_Win32Native_queryPerformanceCounter (JNIEnv *env, jobject obj) {
         LARGE_INTEGER lpCounter;
         ::QueryPerformanceCounter(&lpCounter);
         return (jdouble)lpCounter.QuadPart;
    }Here is the java code:
    import javax.swing.JOptionPane;
    import javax.swing.*;
    import java.net.*;
    import java.awt.*;
    public class Win32Native {
       public native double queryPerformanceFrequency();
       public native double queryPerformanceCounter();
       static {
             System.out.println("Loading library...");
             System.loadLibrary("Win32Native");
             System.out.println("Loaded ok!");
       public static void main(String[] args)  {
          Win32Native nat = new Win32Native();
          // You can call functions here as a quick test
          System.exit(0);
    }

  • How do you create a swimming timer with milliseconds

    Does anyone know how to create a swim timer in milliseconds in Adobe Premiere Pro?
    If you've watched olympic swimming, you've seen the swim timers on the bottom right. I'd like to recreate this in Premiere Pro, showing MM:SS:Milliseconds. (1:25.78).
    I've tried several techniques, but I can't get the milliseconds correct!!
    Here's what I've tried.My media is 29fps.
    1. Create a blank Transparent Video
    2. Add a the "timecode" effect ot the video.
    3. Select the preferences -> show audio time units in the display.
    4. for the Time Display in the time code I used 30 Non-Drop Frame.
    (see a youtube tutorial I followed: http://www.youtube.com/watch?v=Xt3V8JL4LnA)
    This will show correct up to the seconds, but the format for the last is the frame # (up to 30).
    While I've tried changing it to 60 Non-Drop Frames, it only goes up to 60 (again # of frames). How do you get milliseconds?
    The difference between first and second in swim races is milliseconds.
    Thanks for your help.

    Yes. The finish is measured in milliseconds. But there are only 29.97, or maybe 59.94 frames per second in video. So getting to the correct millisecond will be impossible except with great luck.
    In fact, you have probably noticed that you can see the hand about to touch, and see it touching, but not all that often will you see the exact moment it touches.
    So, if you want to create a timer yourself, you can do that, and cheat by using titles to create your numbers. You can make it look like your timer is correct. But it won't be.
    If you want to create 60 different  titles to use to cover up the frames portion of the timecode, the first is 00, then 17, then 33, 50, 67, and keep going... As you can see when you divide 1000 by 60, the real numbers are 16.6667 and 33.33333 but that is just not worth worrying about, I suppose.

  • Measuring time between activation of two boolean

    Hello 
    I want to measure the time elapsed between activation of two boolean variables/indicators. In my code I have DAQ acquiring 2 digital signals which trigger corresponding 2 boolean indicators. Now I am trying to measure time between the event when my first boolean indicator gets the signal  and the event when my second boolean gets the signal. I am attaching my code. I checked DAQ and my indicators everything works fine, but just when I try running the code with the 'elapsed time' part, its not running. Any help will be appreciated.
    Thank You. 
    Attachments:
    Test Code.vi ‏45 KB

    So, feel free to give more detail. I'll just give you a couple thoughts:
    1) The primary issue with your code is that it probably doesn't do what you think it does. How this VI will run is that it will get one data from the DAQmx routine, then pretty much stay in the inner while loop since the event structure has an indefinite timeout. Worse, I don't think changing the value of the boolean controls would trigger the value changed event anyways. In the end, you don't even need the Event Structure to do what you want to do, nor do you need the inner while loop. Just check the values for each iteration of the outer while loop instead and do what you need to do with those.
    2) You are acquiring only one data point at a time. Which is OK if your events are particularly slow with respect to the effective sampling rate of the of loop (which might be able to pick up signals that change on the order of milliseconds or perhaps a bit less). If your signals are faster, you need to think about reading lots of samples at a time (arrays of booleans) and properly triggering your acquisition close to the event it needs to pick.
    3) If your signal is a pulse, make sure that the pulse width of the signal is much longer than than 1 / sampling rate. If it isn't, you could miss the pulse entirely doing this approach.
    4) The faster signals (as long as your have a quick enough sampling rate), the best thing is always to use a counters approach. In many of the DAQ cards and peripherals that NI offers, there are counters that can be driven with the sample clock (one of the fastest clocks on the device) or even a faster time base, and then the 'events' can be used to trigger acquisitions of the counters. Meaning you get exactly what you want: data points that correspond to times when events occur.

  • Measuring time elapsed

    I need to measure the time elapsed between a few commands in a program; is there any finer degree of precision than the millisecond?

    R_Neufeld wrote:
    Thanks, nanoseconds work wonderfully. I did consider simply taking the time in milliseconds over a few cycles and averaging it out, but it would be a little inaccurate considering at least on my computer changes under 4 ms to the clock do not register for some reason (eg I could run Thread,sleep(3) and the time in milliseconds wouldn't change)Check your accuracy assumptions: rerun your tests to see how timing data varies. If there is something I want to time I often loop and do it 100,000 or a million times and average the result.

  • CURRENT TIME IN MILLISECONDS.

    Hi all,
    I need to get the current time in milliseconds. Is there any simple function for that.
    Please do help me.
    Thanking in advance...
    Regards,
    Aswathy.

    What's your OS ?
    Take care, under windows, the prcision will be less than under unix :
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    SQL> select systimestamp from dual;
    SYSTIMESTAMP
    05/04/07 13:04:59,585000 +02:00
    SQL> ---
    SQL> conn H89UCBAC/***@H89UCBAC
    Connected.
    SQL> SQL> select * from v$version;
    BANNER
    Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
    PL/SQL Release 9.2.0.4.0 - Production
    CORE    9.2.0.3.0       Production
    TNS for IBM/AIX RISC System/6000: Version 9.2.0.4.0 - Production
    NLSRTL Version 9.2.0.4.0 - Production
    SQL> select systimestamp from dual;
    SYSTIMESTAMP
    05/04/07 13:05:29,469850 +02:00
    SQL> Nicolas.

  • To get the system time in milliseconds

    i want to get the system time in milliseconds
    eventhough the MLS(milliseconds) is given in the select statement as follows,
    sql>select to_char(sysdate,'MON:DD:YYYY.HH:HH:MI:SS:MLS') "NOW" from dual;
    does not seem to work.
    it throws the error that
    ORA-01821: date format not recognized
    please give a solution
    thanks in advance
    null

    Hi,
    Yes, any of Oracle tools could not provide the milliseconds.
    Then why cant not use external procedures (RPC) and get a time string from OS.
    These are steps:
    1. Create a C shared library.
    (Some times U have to go for OCI programs.)
    Milliseconds provision is there in C. ( use tm struct). Make a string as ur format by using any string functions in C or sprintf(). By using return, return this string.
    Here error may come, if u are using pure C. Better to go for OCI call back methods.
    2. Create oracle library and attach this shared libary with it.
    3. Create external procedure/function and connect this.
    If u want code, I can post it here.
    with regards,
    Boby Jose Thekkanth,
    Dharma Computers(P) Ltd.
    Bangalore-India.
    www.dharma.com.
    null

  • Ni scope measurement time delay

    使用niscope measurement  测量 time delay ,如何使测量更加准确,现在测出来的值的浮动范围很大,另,能不能提供其测量的具体算法编程

    The PXI 1031 is just the chassis and power supply.  It does not read anything.  So I am guessing that the 5105 is doing the measurements.
    What is the resistor value you are using to convert the current to voltage?  Have you verified that the resistor is actually close to the nominal value? Is the voltage in the current loop within the common mode range of the measurement device?  Do you have the loop grounded at two different points?  Does the pressure actually exceed 62 bar?  Does the current from the transducer actually go to 20 mA?
    Your calculation is correct for a 1-5 V input corresponding to 0-100 bar.
    You have several questions which all seem to be related to the same project.  Do you have a good overall plan for the total project? Did someone sit down and create a specification for the hardware and the software? Have the various subsystems been designed in detail before you started developing code and buying hardware?  Do you have a System Architect (Project Manager, or other title) who has a good overall idea of how this thing is supposed to work?
    Without that you will likely continue to be frustrated and not too productive.
    Lynn

  • Measure time of an measurement and if measurement time is less than 90 second wait until 90 second and then proceed to next steps or stop.

    Hi
    I am trying to make a program
          During execute a measurement count the time.
          If  measurement time is more than 90 second proceed to the next steps (or stop the measurement)
          If measurement time is less than 90 second, wait until 90 second and then proceed to next steps or stop
    I appreciate deeply if some help me.

    What sort of measurement are you talking about? What affects the time of your measurement? The very basic description you have is of a state machine and there are numerous examples of that
    1. Actually I would like measure the time of "Alignment" function done by wafer test equipment name Prober ( the model is "UF3000" made by TOKYO SEIMITSU CO., LTD.
    2.. Right now  the "Alignment" function is started when a  GPIB command is written as "N" and wait for resposne 70 in polling.
    Please refer to the attachment for Alignement function if it help you.
    In the attahement
    For Alignment error delay we are using =600
    Alignment counter =30000
    align loop cnt = 30000
    This is a program wriiten by another person and he is not availabe any more. What I am trying to do is
    1.  During execute a "Alignment " function count the time.
    2. If  "Alignment " function time is more than 90 second proceed to the next steps
    3.  If "Alignment " function is less than 90 second, wait until 90 second and then proceed to next steps
    Attachments:
    Alignment function.xlsx ‏153 KB

  • Best way to measure time?

    I have labview 7.0 and SC-2345 with several digital inputs. I have to measure time between digital input(rise or fall)and stop signal comes in my program with compare etc.
    I have tried to measure time with 4 sequences and "get date/time in seconds" and i have also tried to use loop with shift register.
    It seems not to work or accuracy is not enough. so how to do that?

    I am very sorry If you feel I came across unfriendly in any way, my intentions were sincere and I wanted to help you improve your code by pointing out some common mistakes. Believe me, some of my early labVIEW diagrams from 10 years ago are much worse. In the meantime I have accumulated some experience with daily use, but am still learning every day.
    By the way, I an not affiliated with National instruments. This is mostly a peer help forum where LabVIEW users from all over the world help each other improve their coding skills. (Only users with blue names are employed by NI!)
    Certain things are not obvious looking at your code and once the desired functionality is clear we can help you to a more optimized version that actually works. Whatever you are feeding to the "elapsed time" indicator has nothing to do with elapsed time, but counts the iterations of the middle while loop. It is either 1 or 2, depending on the inputs. There has to be a more interesting output (see my next post!).
    For example, let's just look at your inner while loop (see attached image). (1) The number of iterations is known when the loop starts, thus a FOR loop is more appropriate. (2) You are comparing a DBL with an integer using "equal". If by chance the operator would enter a fractional time (e.g. 1000.5), the comparison would never become true and this loop would go on forever. Your program will never finish! Not good!
    An alternative, but safe code is shown below in the image. For integer times, it has exactly the same functionality.
    Apparently, you want to measure elapsed time, and I am guessing elapsed time used by the code in your middle loop. I will attach a simplified example based on your program in the next message here.
    LabVIEW Champion . Do more with less code and in less time .

  • "Measurement time cannot be in the future ".

    Hi Gurus
    I am doing testing for a Computer manufacturing company.When i am trying do confirmation against a production oder via t code CO11N system giving the message "Measurement time cannot be in the future ".
    Could you pls help to resolve this issue.
    Regards
    Sandip

    Hi
    Posting date is the current date.The details of the error given below.
    Measurement time cannot be in the future
    Message no. IR023
    Diagnosis
    The measurement time that you have entered is in the future.
    A measurement reading describes an actual state, and therefore the measurement time cannot normally be in the future.
    System Response
    Processing will not be continued.
    Procedure
    Enter a measurement time in the past.
    If this is an exceptional case, contact your system administrator.
    Procedure for the system administrator
    In exceptional cases, tolerances must be allowed in the entry of measurement times.
    Example:
    Measurements are taken automatically and are then transferred to the SAP System. The system time of the measurement system varies from that of the SAP System for technical reasons.
    You can define an appropriate tolerance level in Customizing for each measuring point category.
    Pls suggest some solution.
    Regards
    sandip

  • How to Measure time taken for a some lines of code in a program?

    Hi
    I have one requirement to measure time taken for executing a  block of code in report . How we can find it ?
    Is there any way to code something in report to caluculate it ?
    Please send solution as early as possible
    thank u

    Ok.. try this code...
    DATA : t1 TYPE i,
    t2 TYPE i,
    delta(16) TYPE p.
    GET RUN TIME FIELD t1.
    PERFORM get_data. "your block of code
    GET RUN TIME FIELD t2.
    delta = t2 - t1.
    delta = delta / 1000000.
    WRITE :/ 'Time elapsed : ', delta , 'Secs'. "time in secs.

  • Q: How to get local time in milliseconds?

    Hi,
    As we know, Labview a G function which can get local date/time in
    seconds. Is there any way to get local date/time in milliseconds? Or it
    also helps if you know there is any similiar function in C/C++.
    Thanks!
    G. Chen
    Ph.D. Candidate
    Ohio Univeristy, Athens, OH
    Nothing can dim the light which shines from within.
    Sent via Deja.com http://www.deja.com/
    Before you buy.

    > As we know, Labview a G function which can get local date/time in
    > seconds. Is there any way to get local date/time in milliseconds? Or it
    > also helps if you know there is any similiar function in C/C++.
    >
    The local time function returns a double precision number.
    Depending on the platform you are using, the number returned
    may have a subsecond amount. This means that you subtract
    and multiply by 1000 to get ms. The platform that returns
    this is Win32, and its resolution is 55ms. Other platforms
    will always return 0.
    It is also sort of possible to synch the ms function with
    the local time function, but this is not very accurate.
    It involves watching the local time function in a loop
    until it changes, and also sample the ms clock to synchronize
    the two clocks.
    From that point on, you can use the ms
    function exclusively, and do the math to get back to local
    time. The problem with this is that the fast clock rolls over
    about every 40 days, the clock may have some drift with the
    local clock, and then there is daylight saving time and time
    zone math, which is always surprisingly complex.
    Greg McKaskle

  • How to measure time delayed measurement

    Hi All:
    I am using TDS3064 scope to measure time delay betwwen two channels (using IVI driver
    complience package 2.2 for scope IVI driver). I look through drivers, but not able to find
    delayed measurement function. Is there any alternate way to measure time delay betwwen two
    channels. If possible please provide me example. I am new to LV programming.
    Thanks
    DBhagat

    You have to understand something about IVI class drivers. To support portability, those functions that are common to a class are what you see in the driver. Some scopes might have the ability to measure time delay between trigger points on different waveforms but many don't. If there is such a function supported by your scope, then you can make a call to the instrument specific driver or a VISA Write/Read. Of course, you then loose the portability feature of IVI which, imho, is about the only reason to use IVI class drivers. What I would recomend is that you do a capture of both traces and then do an analysis of the raw data in LabVIEW. One way to do this is with Trigger Detection for 1 Channel (Analyze>Waveform Monitoring palette). Wire each channels data to the function and obtain the time for each trigger event. The function will return the time for each event that you can use to calculate the difference.

  • Measure time until I get a signal?

    Hello,
    I'm quite new here, and I feel stupid about asking this question, but  I have been trying now for a couple of days to make a VI that measure times until I get a signal in. I'm testing a timers accuracy, so when it turns on the power the VI should show me the time elapsed.
    I'm just fighting with different kind of loops, but can't get any sense from it.
    /gusse

    Hi.
    What kind of a signal is available? Since you post in 'counter/timers', let's assume it is some kind of 5V logical signal, which you can set to high als long as your timer runs.
    Then, what you need is a simple tick count which is controlled by a gate. Use MAX to set-up a counting task. When choosing the counter, you will be shown which lines to hook up to. Measurment then is
    'When Gate is high, count ticks till gate is low.'
    Accuracy and time depends on the tick source. On a dedicated counter card such as 6602, 80 Mhz is available, hence 1/80 000 000 s is duration of one tick. Uncertainty in counting results mostly from the gate not knowing, when a tick comes by as it opens and shuts. So this gives a max error of 2 ticks. Other (probably main) source is signal quality, i.e. slew rate of your logical gate signal.
    Does that help already? If not, please ask further.
    Michael 

Maybe you are looking for

  • Create a New Realm in OID on windows Platform

    Hi I am trying to create a new realm using the following doc located at http://www.oracle.com/technology/obe/obe_as_10g/im/realm_mng/realm.htm but this doc gives instructions about executing shell scripts which is not possible in windows. I got cygwi

  • Invalid number error for bind dialog

    Oracle SQL Developer version 1.1.2.25 BUILD MAIN-25.79 Running under WinXP Issue description: We get an invalid number error when bind variable filled with an enter in the bind dialog

  • HT1338 My imac has no sound can anybody help?

    My IMac was working perfectly this morning and now it has no sound! I´ve checked the volume, the system preferences, built-in audio, without positive results, anybody has a solution?

  • Custom Edit Forms missing Outcome Buttons

    I've created a Content Type "MyTaskContactType" which inherits from Workflow Task (SharePoint 2013) which inherits from Task. I've added an Outcome Choice with a value of "Completed" on "MyTaskContentType".  It shows when I create a Task in workflow

  • Lost gear icon on safari

    there is no "gear Icon" on my safari home page