Request - Convert 24HR script to 12HR

Discussion in 'Jailbreaks and iOS Hacks' started by Krafty, Aug 24, 2010.

  1. Krafty macrumors 601

    Krafty

    Joined:
    Dec 31, 2007
    Location:
    La La Land
    #1
    I'm trying a new lockscreen, but the time on it is in 24HR format. This looks like the JavaScript file for it. Could anyone convert it to 12HR, please?

    http://cl.ly/65204df146c84d06cbc1
    PHP:
    function init ( )
    {
      
    timeDisplay document.createTextNode "" );
      
    document.getElementById("hours").appendChild timeDisplay );
      
    document.getElementById("minutes").appendChild timeDisplay );
      
    document.getElementById("seconds").appendChild timeDisplay );
    }

    function 
    updateClock ( )
    {
      var 
    currentTime = new Date ( );
      var 
    currentHours currentTime.getHours ( );
      var 
    currentMinutes currentTime.getMinutes ( );
      var 
    currentSeconds currentTime.getSeconds ( );

      
    currentHours = ( currentHours 10 "0" "" ) + currentHours;
      
    currentMinutes = ( currentMinutes 10 "0" "" ) + currentMinutes;
      
    currentSeconds = ( currentSeconds 10 "0" "" ) + currentSeconds;
      
      
    document.getElementById("hours").firstChild.nodeValue currentHours;
      
    document.getElementById("minutes").firstChild.nodeValue currentMinutes;
      
    document.getElementById("seconds").firstChild.nodeValue currentSeconds;
    }
     
  2. seanwebb68 macrumors 6502

    Joined:
    Jul 27, 2010
    #2
    I'm not the best with js but try this it might work.

    function init ( )
    {
    timeDisplay = document.createTextNode ( "" );
    document.getElementById("hours").appendChild ( timeDisplay );
    document.getElementById("minutes").appendChild ( timeDisplay );
    document.getElementById("seconds").appendChild ( timeDisplay );
    }

    function updateClock ( )
    {
    var currentTime = new Date ( );
    var currentHours = currentTime.getHours ( );
    var currentMinutes = currentTime.getMinutes ( );
    var currentSeconds = currentTime.getSeconds ( );
    var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";

    currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;
    currentHours = ( currentHours == 0 ) ? 12 : currentHours;
    currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
    currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;

    document.getElementById("hours").firstChild.nodeValue = currentHours;
    document.getElementById("minutes").firstChild.nodeValue = currentMinutes;
    document.getElementById("seconds").firstChild.nodeValue = currentSeconds;
    }
     
  3. Krafty thread starter macrumors 601

    Krafty

    Joined:
    Dec 31, 2007
    Location:
    La La Land
  4. Krafty thread starter macrumors 601

    Krafty

    Joined:
    Dec 31, 2007
    Location:
    La La Land
    #4
    One more request, can you make it display hours like 05:00 instead of 5:00?
     
  5. seanwebb68 macrumors 6502

    Joined:
    Jul 27, 2010
    #5
    Try this

    function init ( )
    {
    timeDisplay = document.createTextNode ( "" );
    document.getElementById("hours").appendChild ( timeDisplay );
    document.getElementById("minutes").appendChild ( timeDisplay );
    document.getElementById("seconds").appendChild ( timeDisplay );
    }

    function updateClock ( )
    {
    var currentTime = new Date ( );
    var currentHours = currentTime.getHours ( );
    var currentMinutes = currentTime.getMinutes ( );
    var currentSeconds = currentTime.getSeconds ( );
    var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";

    currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;
    currentHours = ( currentHours == 0 ) ? 12 : currentHours;
    currentMinutes = ( currentMinutes < 10 ? \"0\" : \"\" ) + currentMinutes;
    currentSeconds = ( currentSeconds < 10 ? \"0\" : \"\" ) + currentSeconds;

    document.getElementById("hours").firstChild.nodeValue = currentHours;
    document.getElementById("minutes").firstChild.nodeValue = currentMinutes;
    document.getElementById("seconds").firstChild.nodeValue = currentSeconds;
    }
     
  6. Krafty thread starter macrumors 601

    Krafty

    Joined:
    Dec 31, 2007
    Location:
    La La Land
  7. seanwebb68 macrumors 6502

    Joined:
    Jul 27, 2010
    #7
    what about this..... if not i'm not sure i'm guessing now so someone else might be able to help if this doesn't work or i'll have to check it out tomorrow

    function init ( )
    {
    timeDisplay = document.createTextNode ( "" );
    document.getElementById("hours").appendChild ( timeDisplay );
    document.getElementById("minutes").appendChild ( timeDisplay );
    document.getElementById("seconds").appendChild ( timeDisplay );
    }

    function updateClock ( )
    {
    var currentTime = new Date ( );
    var currentHours = currentTime.getHours ( );
    var currentMinutes = currentTime.getMinutes ( );
    var currentSeconds = currentTime.getSeconds ( );
    var timeOfDay = ( currentHours < 12 ) ? \"AM\" : \"PM\";
    var currentTimeString = currentHours + \":\" + currentMinutes + \":\" + currentSeconds + \" \" + timeOfDay;

    currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;
    currentHours = ( currentHours == 0 ) ? 12 : currentHours;
    currentMinutes = ( currentMinutes < 10 ? \"0\" : \"\" ) + currentMinutes;
    currentSeconds = ( currentSeconds < 10 ? \"0\" : \"\" ) + currentSeconds;


    document.getElementById("hours").firstChild.nodeValue = currentHours;
    document.getElementById("minutes").firstChild.nodeValue = currentMinutes;
    document.getElementById("seconds").firstChild.nodeValue = currentSeconds;
    }
     
  8. Krafty thread starter macrumors 601

    Krafty

    Joined:
    Dec 31, 2007
    Location:
    La La Land
    #8
    Yeah, clock still isnt show up :-/

    Thanks for your help!
     
  9. seanwebb68 macrumors 6502

    Joined:
    Jul 27, 2010
    #9
    if you send me the lock screen theme i'll have a play and see if i can work it out for you if you like
     
  10. seanwebb68 macrumors 6502

    Joined:
    Jul 27, 2010
    #10
    what about this...

    function init ( )
    {
    timeDisplay = document.createTextNode ( "" );
    document.getElementById("hours").appendChild ( timeDisplay );
    document.getElementById("minutes").appendChild ( timeDisplay );
    document.getElementById("seconds").appendChild ( timeDisplay );
    }

    function updateClock ( )
    {
    var currentTime = new Date ( );
    var currentHours = currentTime.getHours ( );
    var currentMinutes = currentTime.getMinutes ( );
    var currentSeconds = currentTime.getSeconds ( );

    currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
    currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;

    var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";

    currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;
    currentHours = ( currentHours == 0 ) ? 12 : currentHours;

    var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;

    document.getElementById("hours").firstChild.nodeValue = currentHours;
    document.getElementById("minutes").firstChild.nodeValue = currentMinutes;
    document.getElementById("seconds").firstChild.nodeValue = currentSeconds;
    }
     
  11. Krafty thread starter macrumors 601

    Krafty

    Joined:
    Dec 31, 2007
    Location:
    La La Land
    #11
    Well, I decided to use Lock MS. But if you still want the theme I can upload it for you. Thanks for all your effort though.
     
  12. seanwebb68 macrumors 6502

    Joined:
    Jul 27, 2010
    #12
    yeah why not then i can work out what i was doing wrong
     
  13. Krafty thread starter macrumors 601

    Krafty

    Joined:
    Dec 31, 2007
    Location:
    La La Land
    #13

Share This Page