Java time counter ?

Hi,
Is there anyway to set time counter on java?
My friend suggested that I can use util.date at the begining of my program and use it again at the end, after compare these two value, I can get the time period of the program.
However, since util.date will read the time from OS, if user set the OS clock back or forward, I cannot get accurate time.
My program is really sensitive with time (I have to get exactly time the user uses my program.)
Can anyone please have any suggestion about it?
Thank you

> The external class Clock from the javabook package can assist you in your quest.
The internal class Timer from the java.util (or javax.swing) package can assist with his quest and doesn't require external libraries. If the user is interested in external libraries, I'd recommend the Commons Lang StopWatch* class, which is part of the Commons Lang library, which contains a wealth of useful classes.
* http://jakarta.apache.org/commons/lang/api/org/apache/commons/lang/time/StopWatch.html
~

Similar Messages

  • Java Time Counter / Date Class Question

    I am trying to make a program that if a input is recieved it will record the time and when another input is recieved it will record the time as well.
    I am sorry of stupid question:
    1. how do i minus both "timing"? i try to directly minus it, but doesn't seem to work .
    2. in the java Doc it say it can only take up to milli seconds. Is this the smallest time unit i could mesaure?

    I am trying to make a program that if a input is
    recieved it will record the time and when another
    input is recieved it will record the time as well.
    I am sorry of stupid question:
    1. how do i minus both "timing"? i try to directly
    minus it, but doesn't seem to work .
    2. in the java Doc it say it can only take up to milli
    seconds. Is this the smallest time unit i could
    mesaure?1.
    long start = System.currentTimeMillis();
    // do something
    long end = System.currentTimeMillis();
    long elapsed = end - start; //ms
    2.
    No there are smaller.
    Java Tiger (1.5) offers a nano unit for measuring issues.
    currentTimeMillis()
    Returns the current time in milliseconds.
    nanoTime()
    Returns the current value of the most precise available system timer, in nanoseconds.
    good luck!

  • How to create a time counter without using Sleep()?

    I want to create a time counter that would count from 120 minutes and down. I thought about using Sleep() but I have found out that Sleep() is not accurate (so maybe the countdown would take 122 minutes instead of 120 minutes!). What other alternatives do
    I have?
    Note that I want to count 1 second at a time, because I want to show the countdown progress to the user in seconds.

    The next experiment still uses Sleep and waits for approximately 12 seconds, displaying the time each second. However it is probably too overcomplicated compared to time polling:
    const
    int SECONDS_TO_WAIT =
    12;
    ULARGE_INTEGER ul_end;
    FILETIME ft;
    GetSystemTimeAsFileTime( &ft );
    ul_end.LowPart = ft.dwLowDateTime;
    ul_end.HighPart = ft.dwHighDateTime;
    ul_end.QuadPart += 10LL *
    1000 *
    1000 * SECONDS_TO_WAIT;
    for( ;; )
    FILETIME ft;
    GetSystemTimeAsFileTime( &ft );
    ULARGE_INTEGER ul;
    ul.LowPart = ft.dwLowDateTime;
    ul.HighPart = ft.dwHighDateTime;
    if( ul.QuadPart >= ul_end.QuadPart )
    break;
    SYSTEMTIME st;
    FileTimeToSystemTime( &ft, &st );
    Sleep( 1000 - st.wMilliseconds );
    GetSystemTime( &st );
    if( st.wMilliseconds >
    500 )
    FILETIME ft;
    SystemTimeToFileTime( &st, &ft );
    ULARGE_INTEGER ul;
    ul.LowPart = ft.dwLowDateTime;
    ul.HighPart = ft.dwHighDateTime;
    ul.QuadPart += 10LL *
    1000 *
    1000;
    ft.dwLowDateTime = ul.LowPart;
    ft.dwHighDateTime = ul.HighPart;
    FileTimeToSystemTime( &ft, &st );
    // show the time
    SystemTimeToTzSpecificLocalTime( NULL, &st, &st );
    printf( "%02i:%02i:%02i\n", st.wHour, st.wMinute, st.wSecond

  • How to add an "age / time counter" into DW?

    Can anyone assist on how to add an age / time counter into DW?
    In other words to say "Child X is now a years, b months old"? or "Product Z was launched A years B months ago"? Or, on the other hand, "You only have Z days & Y minutes left to enter"? With it updating in real time?
    Apologies in advance if this is a silly / obvious question but I just can't seem to do it!

    This isn't something you would add to DW, you would need to add it to your webpages. You would do this with javascript. Search the web for
    'javascript countdown timer' for plenty of examples.

  • I need to play back a video-recording i have taken myself and have it show the time count in seconds on the play back. Can you help?

    I need to play back a video-recording that I have taken myself and have it show the time counter in secs/minutes in the playback. Can anyone help?

    the movie editing app "Avid Studio" displays a time counter, as does the Pinnacle editing app.  Oddly enough, I movie does not.  (unless I have it somehow turned off.)

  • Java Timer problem

    hi,
    i am finding some problem using java timer.
    I have a server program that regularly needs to save its data. i want to do it using java Timer.
    i got the following sample code as an example. it works perfectly but how can i send new data each time to save?
    import java.util.Timer;
    import java.util.TimerTask;
    import Core.General;
    public class test_timer {
    public static void main(final String args[]) {
    final Timer timer = new Timer();
    timer.scheduleAtFixedRate(new ttask(), 3000, 3000);
    class ttask extends TimerTask
    public void run() {
    System.out.println("hello ");
    As an example i would like to send current time to the timer task and print it. how is it possible?
    regards
    tom

    For the current time you can just go ahead and do the following call:
    System.currentTimeMillis();
    This will get you the current time in milleseconds.
    When timer is called, get the crrent time and print it.
    Hope this helps.
    hi,
    i am finding some problem using java timer.
    I have a server program that regularly needs to save
    its data. i want to do it using java Timer.
    i got the following sample code as an example. it
    works perfectly but how can i send new data each time
    to save?
    import java.util.Timer;
    import java.util.TimerTask;
    import Core.General;
    public class test_timer {
    public static void main(final String args[]) {
    final Timer timer = new Timer();
    timer.scheduleAtFixedRate(new ttask(), 3000,
    000, 3000);
    class ttask extends TimerTask
    public void run() {
    System.out.println("hello ");
    As an example i would like to send current time to the
    timer task and print it. how is it possible?
    regards
    tom

  • USB 8451 no timer / counter ?

    Hi all,
    i´m not sure if i´m in the right topic now, but i found no answer with the search function.
    I tried to generate an digital pulse using timer/counter functions with Labview 8.5 and an USB 8451, but it didn´t work.
    Is it possible that the USB 8451 doesn´t support timer / counter signals?
    Thanks for all your answer!

    Hi AK2DM,
    thanks for catching this one. I missed the important piece of information that the original poster would like to generate pulses. We have a KB-entry for this. You could also generate software-timed pulses with the 8451. The jitter (timing deviation), as you mentioned, could be a problem. The same issue arises with the 6501 I mentioned!
    For generating pulse trains I would recommend a basic E or M series device such as the 6210 USB.
    If you have further questions, don't hesitate to ask.
    Best regards,
    Peter
    Peter A.
    Field Sales Engineer, NI Germany

  • I always need to see the time counter on the music player, is that possible?

    As a spinning instructor I need to see the time counter on the music player all the time. Now it dissepears after a short time and I need to touch it to see it again and that is not good! I also wish that it was bigger numbers on the counter so I easy can see how long time it's lest on the songs.
    Ideas anyone?

    By default the screen display will dim in about 20 seconds to conserve the battery. And I cannot find any setting to inhibit this function. I am afraid there is no way you can keep the screen bright and enlarge the numbers on the timer.

  • Can you add a time counter

        I know you can view the project length in project info, but is there a way for the user to see a time count?
    Most viewers have this feature.
    Captivate 7

    It is a pretty old post, but still valid: http://blog.lilybiri.com/display-time-information

  • How to synchronize two timer/counter tasks?

    Hi,
    I'm programming DAQmx through the nicaiu.dll with Matlab. I'm trying to start two different tasks, each controlling ctr0 and ctr1, respectively. Both timer/counter tasks should start on a common trigger, in my case /Dev/PFI0. Having searched the forum, I do understand that both tasks can't be triggered off PFI0. Instead, I probably need to trigger one of my tasks on a signal that turns on whenever the first task starts. My question is; What signal can inform my ctr1 task that my ctr0 has started? I basically want these two tasks synchronized, but not pulse by pulse since the pulse trains are quite different.
    Trying to trigger both off PFI0 results in a resource conflict. Triggering ctr1 on ctr0gate doesnt work either.
    Also, I need ctr1 to trigger on when the ctr0 tasks starts, i.e. not when the first ctr0 pulse appaers!
    Thanks,
    Per

    Thanks Ryan.
    I made some changes to my code now and it appears I CAN trigger both counters off PFIO (on an E-Series board). I only recently converted all my Traditional code into DAQmx, and got lost in my tracks. I was trying to generate finite pulse trains on both counters, and had used Finite timing on the counters to generate finite retriggerable pulse trains, without knowing that tied up the second counter. I solved this now using Pause Triggers instead. In the case where I generate single retriggerable pulses I still use a Start Trigger, and I can now Start BOTH counters using DAQmxCfgDigEdgeStartTrig and listening to PFIO with both counters (each counter running off a separate task).
    Sorry, I got things confused, and your solution isnt required anymore. Similarly to your solution, though, I have always used a (real) analog output routed externally to the PFI0 pin on my E-Series board as the synchronizing trigger. However, if I could avoid the external wiring it would be nice, so I will explore your solution a bit more
    I am not familiar with the concept of a 'dummy' task/channel. Can you point me to more documentation on this?
    I already use the analog inputs on this board from another app. Will creating a dummy AI tie up all analog inputs, so I can't then access my physical analog inputs from other applications (on the same board)?
     - Per

  • Solution for Accumulative time counter

    Hi,
    I am developing an online training web application in MVC framework,
    i have to maintain a accumulated time counter for every user . for example 400 hrs a course means (00.00.00 to 200.35.45) (hr/minute/seconds) format .I will have to count for the entire session for every time user login.
    first day: 00.00.00 to 02.35.45
    second day :02.35.45 to 03.35.45
    need solution.
    Regards
    gopi.

    Convert to (milli)seconds and calculate it. There are no API's of use for you AFAIK.

  • How to create a time counter

    Hello expertsl,
    I have a new challenge on board.
    I have a form that is automatically popped up. Now on the form, i need to insert a timer that as soon as it pops out, the timer starts and then i have to enter some data in the form and as soon as i press the save button, the timer records the time count and then stores it in a table.
    Any suggestion are the most welcome...
    Thank you

    As Hoek said, this is not a Forms forum.
    However, the problem is not really unique to Forms and a timer itself is not needed.
    A timer is a kernel object that fires at specific intervals and each time around executes a callback routine. This allows one to update or process at specific intervals.
    You do not need a timer as you are interested in time elapsed - which means that on the creation of the form you need to get the current time. When the save button is clicked you again get the current time. The data that you are interested in is the time difference between these two.
    Remember that timers are expensive objects to create ito kernel resources. Some operating systems limit the total number of timers that can be created. In general, it is not a good idea to create a timer unless it is the best technical solution for the problem. And you do not need a timer determine a time elapse. You simply need code in the constructor of the form and code in the save events of the form. Nothing more.

  • A time counter for the whole project

    Can you tell me is there any way to get the overall project time  as a time counter in the playback controls? Or viewed somewhere on Captivate?
    I need to know at which time a particular slide is appearing in a video. I can only find time duration  per slide or one overall time for the project.

    If you dont like the TOC, here you can find some other ideas:
    http://blog.lilybiri.com/display-time-information

  • How do I overlay a timer counting down on a Keynote slide?

    Hello!
    I am searching for a way (app or otherwise) to have a timer counting down while in "full screen" mode in Keynote. I am an urban educator, and I've found it very effective in having a stunning image on the smartboard via Keynote, in order to focus engagement while the students enter my classroom. I would love to also have a timer overlayed on that slide somewhere (right hand corner likely) counting down - so students know how much time they have to socilize and become situated before class "officially" begins.
    Appreciate any guidance!
    Best
    Biros

    My brain got fried with all of the previous SWFLoader positioning and centering - so much that I had to stop and clear my head and then this became an easy case of putting the HGroup and the Logo inside a BorderContainer.  I had inadvertently placed the Logo inside of HBox.

  • Java 8: Pb with new java.time api

    Hello,
    I'm trying to use the new java.time api that comes with Java 8 (I already know joda-time).
    I'm using the latest build B124.
    I've a String "01/08/2012_00:00:01", I know that the time ref. is UTC, and I want to convert it to an 'Instant';
    I tried:
    DateTimeFormatter FORMAT_DT = DateTimeFormatter.ofPattern("dd/MM/yyyy_HH:mm:ss").withZone(ZoneOffset.UTC);
    Instant instant = Instant.from(FORMAT_DT.parse("01/08/2012_00:00:01"));
    But it fails with following error:
    java.time.DateTimeException: Unable to obtain Instant from TemporalAccessor: {},ISO resolved to 2012-08-01T00:00:01 of type java.time.format.Parsed
         at java.time.Instant.from(Unknown Source)
    I don't understand what's wrong with my code, and I can't figure out how I should proceed to convert the String to an Instant ...
    Any suggestion welcome,
    Best regards,
    Bernard.

    Originally you stated this:
    I don't understand what's wrong with my code,
    So naturally we focused on how to "understand what's wrong' with your code.
    You will never learn to troubleshoot problems if you just throw your hands up in the air and ask for help just because a complex series of steps doesn't complete successfully. 
    Break the process into its individual steps and check the results of each step to identify which step is FIRST producing an error.
    When a complex or multi-step process has an error you start checking the individual steps of the process to see how far it gets successfully.
    I would expect that converting a String to an Instant should be a basic/simple need, so it should be possible to do it in two lines of code; for the time being, the only way I found is to use a LocalDateTime intermediate variable, which seems quite verbose, and I'm wondering if someone knows a better way to do it, and would be willing to share it here.
    Just a technical distinction: your latest example using a LocalDateTime intermediate variable CAN be done in one line of code by just using dot-notation to avoid creating an explicit intermediate variable. But that variable will still be created implicitly behind the scenes.
    Converting a String to an Instant might be considered a basic/simple need but the set of functionality related to dealing with times, dates, calendars, etc is extremely complex. It makes much more sense to develop the requisite functionality in modules.
    Especially when introducing new functionality such as the 'Instant' class are related package elements introduced in 1.8. That functionality builds on what came before and parsers already existing that know how to deal with all of the possible String variants and formatting options and so on.
    Since that work CAN BE done on-the-fly using dot notation and anonymous implicit intermediate classes there isn't much need to reinvent that functionality in the new classes. If certain uses become standard new methods can always be added (e.g. to the Instant class) that will 'appear' to do things in one step.
    And, being an early adopter release, you can always file a 'bug' or enhancement request from the 1.8 download page. That page has links for 'Report Bugs' and 'Feedback forum' that you can use.
    In this current forum no one can give you an 'official' answer as to why something was implemented a particular way and/or whether that implementation is a 'bug' or was designed to work that way. Only Oracle can do that.

Maybe you are looking for

  • How do I fix lag on Mid 2010 MacBook Pro 13"?

    I have a Mid 2010 MacBook Pro 13'' and lags often. I empty my rubbish bin every time its full, I close programs that are not in use at the moment and even refresh once in a while. For example, I only use Google Chrome and its still lagging even thoug

  • Lightening to HDMI not working after recent update

    I recently updated my Ipad and now my Lightening to HDMI adapter does not seem to work.  It was working fine up until the most recent update.   I know that the HDMI cable works and all the other connections are fine b/c it works fine when plugged int

  • Hierarchal tree in FORMS

    Hi, I have a hierarchal tree table that I want to represent using forms (insert and update data in the tree table). Are there any LINKS or documentation that can help me with my little project :-) Thanks, Marc.

  • Configration failed

    Failed to create Sample Data An exception of type System.Data.SqlClient.SqlException was thrown. Addition Exceptional information: Cannot open database "User Profile Service Application_ProfileDb_90a125----------------" requested by the login. The lo

  • Ignore not numbers values

    Hi, I have a column containing a number stored as text, and I want to do some calculation on that column. So I'm using TO_NUMBER function, but the problem that some values are not really numbers like '4A' so I want to bypass or ignore the calculation