Gadget Help; change 24-hour clock into 12-hours


  1. Posts : 9
    Windows 7 Home Premium 64-bit
       #1

    Gadget Help; change 24-hour clock into 12-hours


    I downloaded the StarCraft II Clock from the Windows 7 Desktop Gadget gallery, only to find it's a 24-hour clock and has no settings. How would I change it - presumably by changing its java file - so that it is a 12-hour clock instead?
      My Computer


  2. Posts : 1,872
    Windows 10 Pro x64, Windows 8.1 Pro x64, Windows 7 Ultimate x64 SP1,
       #2

    I do not know if it is possible. You might ask the creator.

    However, I like the Preston Clock gadget myself. It can be set up in 12 or 24 hrs.

    Windows Gadget: Presto's Sidebar Clock (Preston Hunt)
      My Computer


  3. Posts : 9
    Windows 7 Home Premium 64-bit
    Thread Starter
       #3

    Point is, I quite like the look of that clock.
      My Computer


  4. Posts : 1,872
    Windows 10 Pro x64, Windows 8.1 Pro x64, Windows 7 Ultimate x64 SP1,
       #4

    See the next post.
    Attached Thumbnails Attached Thumbnails Gadget Help; change 24-hour clock into 12-hours-clk.png  
    Last edited by pbcopter; 04 Feb 2016 at 12:17.
      My Computer


  5. Posts : 1,872
    Windows 10 Pro x64, Windows 8.1 Pro x64, Windows 7 Ultimate x64 SP1,
       #5

    These are the required changes to get the clock to be 12 Hr instead of 24 HR.

    A .gadget file is just a compressed file (.zip). It can be opened with 7Zip and when editing is done recompressed to a zip file again. Select all the files that were extracted, including the modified SC2Clock.html file, and then recreate the zip file. Then rename the .zip file to .gadget to install.
    You can edit the SC2Clock.html with Notepad.

    Original Clock code in file SC2Clock.html

    Code:
    function updateClock ( )
    {
      var currentTime = new Date ( ); 
    
      var currentHours = currentTime.getHours ( );
      var currentMinutes = currentTime.getMinutes ( );
    
      currentHours = ( currentHours < 10 ? "0" : "" ) + currentHours;
      currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
    
      var currentTimeString = currentHours + ":" + currentMinutes;
    
      document.getElementById("gadgetContent").firstChild.nodeValue = currentTimeString;
    }
    Modified Clock code in file SC2Clock.html
    Changes/Additions to get 12HR clock are in bold type.

    Code:
    function updateClock ( )
    {
      var currentTime = new Date ( );
    
      var currentHours = currentTime.getHours ( );
      var currentMinutes = currentTime.getMinutes ( );
      var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM"; 
     
     currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;   
      currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;
      currentHours = ( currentHours == 0 ) ? 12 : currentHours;
    
    
    
      var currentTimeString = currentHours + ":" + currentMinutes + " " + timeOfDay;
     
      document.getElementById("gadgetContent").firstChild.nodeValue = currentTimeString;
    }
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 22:37.
Find Us