Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Outputting time to screen

  • 04-02-2003 7:09pm
    #1
    Registered Users, Registered Users 2 Posts: 1,466 ✭✭✭


    this is what i have so far only it seems to be going very very fast:

    current = System.currentTimeMillis();
    secs = current%1000;
    secs = secs%100;
    current = current/1000; //puts it into seconds
    mins = current%60;
    current = current/60; //puts it into minutes
    hours = current%60;
    current = current/60; //puts it into hours
    current = current/24; //puts it into days
    current = current/365; //puts it into years

    then i output the hours, mins, and secs , only there the wrong values and when i reload it they have advanced away too much.

    When I outputed current it did however give 33 which is right.
    Anyone got any tips on synchronizing the time correctly.


Comments

  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    If you look at the java API you'll see that System.currentTimeMillis() gives "the difference, measured in milliseconds, between the current time and midnight, January 1, 1970". Given the calculations above, this is more than likely your problem....


  • Registered Users, Registered Users 2 Posts: 1,931 ✭✭✭Zab


    Hi,

    Your maths are way off. Below would be more what you are looking for...
    long current = System.currentTimeMillis();		
    // Change to seconds
    current /= 1000;
    // Find the seconds
    long secs = current%60;
    // Change to minutes
    current /= 60;
    // Find the minutes
    long mins = current%60;
    // Change to hours
    current /= 60;
    // Find the hours
    long hours = current%24;
    // Change to years
    current /= 24*365; 
    

    Every line after the "change to" comments changes the current value to a different value since 1970.... such as hours since 1970 etc.

    However, unless you have a particular reason for doing it in this way ( college project - have to show knowledge of how it works, etc. ), then you should look into the Calendar class.

    Zab


  • Registered Users, Registered Users 2 Posts: 1,466 ✭✭✭FastFullBack


    Thanks found the calender class and got that going.Any ideas on how to keep this time value continously updated?
    Thanks


  • Registered Users, Registered Users 2 Posts: 2,013 ✭✭✭lynchie


    Look up the API on using Threads. Loads of tutorials on them too..


Advertisement