Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: analogue clock coding an additional time report

  1. #1
    Junior Member
    Join Date
    Aug 2023
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default analogue clock coding an additional time report

    Hi all, first time posting here...

    I have built this analogue clock (code below) but I can't get my head around how to add an additional hand that displays a 24 hour cycle. I'm pretty sure there isn't provision for both 12 hour and 24 hour hands in java but obviously, I could be wrong. If that is the case, is there a crafty way of duplicating the 12 hour call and altering the rotation accordingly?

    Thank you all in advance.

    <script>
    const secondHand = document.querySelector('.second-hand');
    const minsHand = document.querySelector('.min-hand');
    const hourHand = document.querySelector('.hour-hand');

    /*const subHand = document.querySelector('.sub-hand');*/


    function setDate() {
    const now = new Date();

    const seconds = now.getSeconds();
    const secondsDegrees = ((seconds / 60) * 360) + 90;
    secondHand.style.transform = `rotate(${secondsDegrees}deg)`;

    const mins = now.getMinutes();
    const minsDegrees = ((mins / 60) * 360) + ((seconds/60)*6) + 90;
    minsHand.style.transform = `rotate(${minsDegrees}deg)`;

    const hour = now.getHours();
    const hourDegrees = ((hour / 12) * 360) + ((mins/60)*30) + 90;
    hourHand.style.transform = `rotate(${hourDegrees}deg)`;

    }

    setInterval(setDate, 1000);

    setDate();


    </script>

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: analogue clock coding an additional time report

    Looks like javascript code. Java is a different language
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Elevator simulation in event time, not clock.
    By Leeness in forum What's Wrong With My Code?
    Replies: 11
    Last Post: April 11th, 2014, 06:31 AM
  2. Online Employee Time Clock
    By DkParks in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 20th, 2013, 12:25 PM
  3. Replies: 1
    Last Post: September 15th, 2011, 02:38 PM
  4. Analogue Clock Problem
    By gargamel7 in forum What's Wrong With My Code?
    Replies: 48
    Last Post: September 2nd, 2011, 01:21 PM