Results 1 to 9 of 9

Thread: 12h to 24h clock

  1. #1
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 12h to 24h clock

    Hello. I got this script(attached) and it's currently in a 12h format but I'd like to change it to 24h, however, I'm really not good at coding. Can anyone help me?

    Thanks in advance.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    There is no file or text attached. We can probably help though!
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Oh oops. I guess it didn't upload..

    Here it is

  4. #4
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Nothing in the file..
    Corrections to my coding/thoughts welcome.

  5. #5
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Oh come on really? I just downloaded it and I could see it? Weird..Anyways, here it is:


    <html>
    <head><title>newclock</title><base href="Private/"/></head>

    <style>

    SPAN#clock
    {
    font-family: Helvetica;
    font-weight: bold;
    color: #575a5b;
    text-shadow: 0px -1px 0px rgba(0, 0, 0, 0.7);
    /*text-shadow: #ac7a00 0px 1px 0px;*/
    font-size: 26px;


    }

    SPAN#ampm
    {
    font-family: Helvetica;
    font-weight: bold;
    color: #575a5b;
    text-shadow: 0px -1px 0px rgba(0, 0, 0, 0.7);
    /*text-shadow: #ac7a00 0px 1px 0px;*/
    font-size: 15px;

    }

    TD#date
    {
    font-family: Helvetica;
    font-weight: bold;
    text-align: left;
    color: #575a5b;
    text-shadow: 0px -1px 0px rgba(0, 0, 0, 0.7);
    /*text-shadow: #FFFFFF 0px 1px 0px;*/
    font-size: 13px;
    text-transform: uppercase;

    }

    </style>

    <script type="text/javascript">
    <!--
    var this_weekday_name_array = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
    var this_month_name_array = new Array("January","February","March","April","May","June","July","August","September","October","November","December") //predefine month names


    var this_date_timestamp = new Date()

    var this_weekday = this_date_timestamp.getDay()
    var this_date = this_date_timestamp.getDate()
    var this_month = this_date_timestamp.getMonth()
    var this_year = this_date_timestamp.getYear()

    if (this_year < 1000)
    this_year+= 1900;
    if (this_year==101)
    this_year=2001;

    var this_date_string = this_weekday_name_array[this_weekday] + " " + this_date + " " + this_month_name_array[this_month]//concat long date string

    // -->
    function init ( )
    {
    timeDisplay = document.createTextNode ( "" );
    document.getElementById("clock").appendChild ( timeDisplay );
    }

    function updateClock ( )
    {
    var currentTime = new Date ( );

    var currentHours = currentTime.getHours ( );
    var currentMinutes = currentTime.getMinutes ( );
    var currentSeconds = currentTime.getSeconds ( );

    // Pad the minutes and seconds with leading zeros, if required
    currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
    currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;

    // Choose either "AM" or "PM" as appropriate
    var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";

    // Convert the hours component to 12-hour format if needed
    currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;

    // Convert an hours component of "0" to "12"
    currentHours = ( currentHours == 0 ) ? 12 : currentHours;

    // Compose the string for display
    var currentTimeString = currentHours + ":" + currentMinutes;

    // Update the time display
    document.getElementById("clock").firstChild.nodeValue = currentTimeString;
    }

    function init2 ( )
    {
    timeDisplay = document.createTextNode ( "" );
    document.getElementById("ampm").appendChild ( timeDisplay );
    }

    function amPm ( )
    {
    var currentTime = new Date ( );

    var currentHours = currentTime.getHours ( );

    // Choose either "AM" or "PM" as appropriate
    var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";

    // Convert the hours component to 12-hour format if needed
    currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;

    // Convert an hours component of "0" to "12"
    currentHours = ( currentHours == 0 ) ? 12 : currentHours;

    // Compose the string for display
    var currentTimeString = timeOfDay;

    // Update the time display
    document.getElementById("ampm").firstChild.nodeValue = currentTimeString;
    }

    function init3 ( )
    {
    timeDisplay = document.createTextNode ( "" );
    document.getElementById("calendar").appendChild ( timeDisplay );
    }

    function calendarDate ( )
    {
    var this_weekday_name_array = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
    var this_month_name_array = new Array("January","February","March","April","May","June","July","August","September","October","November","December") //predefine month names

    var this_date_timestamp = new Date()

    var this_weekday = this_date_timestamp.getDay()
    var this_date = this_date_timestamp.getDate()
    var this_month = this_date_timestamp.getMonth()

    //document.getElementById("calendar").firstChild.nodeValue = this_weekday_name_array[this_weekday] + " " + this_date + " " + this_month_name_array[this_month]//concat long date string

    document.getElementById("calendar").firstChild.nodeValue = this_weekday_name_array[this_weekday] + "," + " " + this_month_name_array[this_month] + " " + this_date //concat long date string
    }

    // -->
    </script>

    </head>


    <body >





    <table style="position: absolute; top: 310px; left: 105px; width: 180px; height: 461px;" cellspacing="0" cellpadding="0" align="right">
    <tr align="left" valign="top" border="0" cellpadding="0">
    <td height="12" valign="top" margin-left="120" >
    <span id="clock">
    <script language="JavaScript">updateClock(); setInterval('updateClock()', 1000 )</script></span><span id="ampm">
    <script language="JavaScript">amPm(); setInterval('amPm()', 1000 )</script>
    </span>
    </td>
    </tr>
    <tr>
    <td id="date" valign="top">
    <span id="calendar">
    <script language="JavaScript">calendarDate(); setInterval('calendarDate()', 1000 )</script>
    </span>
    </td>
    </tr>
    </table>
    <object data="WeatherWidget/WeatherWidget.html" type="text/html" height="480" width="320">
    <p></p>
    </object>

    </body>
    </html>

  6. #6
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,920
    Thanks
    2
    Thanked 267 Times in 262 Posts

    Default

    Hi there intakep,

    and a warm welcome to these forums.

    You seem to have a lot of code there.

    Try this simplified example...
    Code:
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta name="language" content="english"> 
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    
    <title>twenty four hour clock with date</title>
    
    <style type="text/css">
    body {
        margin:0;
        padding:0;
        font-family:helvetica,sans-serif;
        font-weight:bold;
        color:#575a5b;
        text-shadow:0 -1px 0 rgba(0,0,0,0.7);
     }
    #currenttime {
        margin:310px 0 0 105px;
        font-size:26px;  
     }
    #currenttime span {
        padding-left:5px;
        font-size:15px; 
     }
    #currentdate {
        margin-left:105px;
        font-size:13px; 
        text-transform:uppercase;
     }
    </style>
    
    <script type="text/javascript">
    
    function displayDate(){
    
       month=['January','February','March','April','May','June','July','August','September','October','November','December'];
       day=['Sunday','Monday','Tuesday','Wednsday','Thursday','Friday','Saturday']; 
    
       dte=new Date();
       yy=dte.getUTCFullYear();
       mm=dte.getMonth();
       dd=dte.getDate();
       dy=dte.getDay();
       hr=dte.getHours();
       mn=dte.getMinutes();
    
    if(hr<10){
       hr='0'+hr;
     }
    if(mn<10){
       mn='0'+mn;
     }
       time=hr+':'+mn;
       date=day[dy]+', '+month[mm]+' '+dd+', '+yy;
    
       document.getElementById('currenttime').firstChild.nodeValue=time;
       document.getElementById('currentdate').firstChild.nodeValue=date;
    
    setTimeout(function(){displayDate()},1000);
     }
    
    if(window.addEventListener){
       window.addEventListener('load',displayDate,false);
     }
    else { 
    if(window.attachEvent){
       window.attachEvent('onload',displayDate);
      }
     }
    
    </script>
    
    </head>
    <body>
    
    <div id="currenttime">&nbsp;<span>HRS</span></div>
    <div id="currentdate">&nbsp;</div>
    
    </body>
    </html>
    
    coothead

  7. #7
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks so much! works great

  8. #8
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,920
    Thanks
    2
    Thanked 267 Times in 262 Posts

    Default

    No problem, you're very welcome.

  9. #9
    Join Date
    Sep 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    @coothead

    I am impressed by your helpful. On every other forum intakep would just get an information:

    "try to use google and find the right solution yourself".

    It is hard to find someone really helpful on forums today.
    Last edited by rkoziol7; 09-22-2010 at 11:11 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •